Remote Functions

0

  • RemoteFunction is a two-way communication (vs one-way for a RemoteEvent)
  • Code that calls it waits to hear back before going to the next line
Step 1: Create ReplicatedStorage Event
  • Add RemoteFunction and call it DeleteBombFunction
Step 2: Create LocalScript
StarterPlayer/StarterPlayerScripts/LocalScript
local RS = game:GetService("ReplicatedStorage")
local DeleteBomb = RS:WaitForChild("DeleteBombFunction")
local UIS = game:GetService("UserInputService")

function doIt(input, gameProcessedEvent)
    if input.KeyCode == Enum.KeyCode.R then
        print("R pressed!")
        local Bomb = game.Workspace:FindFirstChild("Bomb")
        if Bomb then
            DeleteBomb:InvokeServer(Bomb)
            print("Bomb Deleted") --will not print for 5 seconds!
        end
    end
end

UIS.InputBegan:Connect(doIt)
Step 3: Create a server script
ServerScriptService/Script
local RS = game:GetService("ReplicatedStorage")
local DeleteBomb = RS:WaitForChild("DeleteBombFunction")

DeleteBomb.OnServerInvoke = function(player, part)
    part:Destroy()
    wait(5) --arbitrary delay to show how remote functions work
end

https://developer.roblox.com/en-us/articles/Remote-Functions-and-Events

https://www.youtube.com/watch?v=GwhPXyYKkwU&list=PLhieaQmOk7nIoGnFoACf33M3o0BOqB38a&index=9

  • 0 posts
  • 0 subtopics
  • 13 days ago by vince