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

Local-script to script changing variables?

I'm working an admin script and when I pass over "victim" it turns from "Player2" to "Player1", kicking the player registering the kick event. I've never had this issue before, it doesn't print as like "attempt to index a nil value" (already dealt with that) but the variable changes when it's passed over to the server script and I cannot figure out why.

-- Server script snip
function onKickEvent(Player,victim)
	if not IsStaffMember(Player) then return Player:Kick("Stop exploiting.") end
	local event = "_K"
	print(victim.Name, Player.Name) -- Prints "Player1 Player1"
	_M:FireClient(Player,victim,event)
	game:GetService("Players")[victim.Name]:Kick("Do not break game rules. Kicked by "..Player.Name)
end
-- Local script snip
script.Parent.MouseButton1Click:Connect(function()
	for i,v in pairs(Staff) do
		if not Player.Name == v then return end
	end
	if panel.Value.Value == "a" then
		local victim = game:GetService("Players"):FindFirstChild(script.Parent.Parent.box.Text)
		print(victim.Name, Player.Name) -- Prints Player2 Player1
		kick:FireServer(Player,victim)
	end
end)

1 answer

✓ Accepted answer

The player who calls the event is automatically passed through. Here's an example.

If I call :FireServer("Hello"), the server knows I called it.

The server recieves game.Players.chexburger and "Hello" automatically.

The client DOES NOT need to specify who they are. The server already knows who the client is.

Client:

event:FireServer("Hello")

Server:

event.OnServerEvent:Connect(function(player,message)
	print(player.Name) --> chexburger
	print(message) --> Hello
end)

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