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

RemoteEvent not getting correct function?

i was trying to make a add command which I needed to use remotevent for, but it isnt going correct and give out eror. why tough?

--localscript
game.ReplicatedStorage.kickplrreason:FireServer(reason)

--script normal
game.ReplicatedStorage.MathAdd.OnServerEvent:Connect(function(reason)
	otherplr:Kick(reason)
end)

but then it puts the reason as my name??? why???

2 comments

0

You're trying to get "reason" from a different remote event (notice the names "kickplrreason" and "MathAdd").

0

oh ok thx

1 answer

✓ Accepted answer

Hey there! So, your problem is this:

RemoteEvents passed on the player who fired the event as the first function, then all the selected functions. So let's say I stepped on a brick which fires a RemoteEvent.

local remotefire = game.ReplicatedStorage.RemoteEvent
script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		remotefire:FireServer()
	end
end)

Now here, in my server script, this is what happens:

local remotefire = game.ReplicatedStorage.RemoteEvent
remotefire.OnServerEvent:Connect(function(player) -- Function 'player' is here because it is correspondent to the player who fired the RemoteEvent.
	print(player.Name) -- This would make my name be printed.
end)

So, in your case, you would have to do:

game.ReplicatedStorage.MathAdd.OnServerEvent:Connect(function(player, reason)
    otherplr:Kick(reason)
end)

1 comment

0

ok thx ur answer plus the other guy answer made me get it thx

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