Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Question about remote events?

Asked by 6 years ago

When using remote events should the check that checks if the player can perform the action be in the server script or local script?

workspace.Part.Touched:Connect(function(hit)
    if hit.Parent.Name == "Part" then
        print("A")
        game.ReplicatedStorage.RemoteEvent:FireServer()
    end
end)


Should this be in the local script with fire server or a server script with onserverevent? Which is the most safest for no exploiters?

1 answer

Log in to vote
0
Answered by 6 years ago

You shouldn’t handle the Touched event on the client. If you really wanted to fire something with server scripts and server scripts only, use a BindableEvent. These are for server-to-server communication or for client-to-client communication. These are not to make your game FE compatible.

local bindable = game.Workspace.Event
local part = game.Workspace.Part
local plrs = game:GetService"Players"

function getPlayerFromChar(char)
    if plrs:GetPlayerFromCharacter(char) then
        return plrs:GetPlayerFromCharacter(char)
    end
end

bindable.Event:Connect(function()
    -- code
end)

part.Touched:Connect(function(part2)
    if getPlayerFromChar(part2.Parent) then
        local plr = getPlayerFromChar(part2.Parent)

        if plr then
            bindable:Fire()
        end
    end
end)
1
Thanks Thepoint13 99 — 6y
0
no problem User#19524 175 — 6y
Ad

Answer this question