Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Question about remote events?

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

✓ Accepted answer

###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)

2 comments

1

Thanks

0

no problem

This discussion is preserved as it was. New answers, comments, and votes are closed.