Remote Events target the wrong user

I have a Admin GUI that allows me to kick, ban, and kill selected players. When using it, all the actions are taken against me instead of the target.

-- Admin Script
AdminEvents.Kick.OnServerEvent:Connect(function(Player: Player, offender: Player)
	if permissionCheck(Player, "moderator") then
		if permissionCheck(offender, "owner") then return end
		ModService.Kick(offender, "Kicked by administration.")
	end
end)

AdminEvents.Ban.OnServerEvent:Connect(function(Player: Player, offender: any)
	if permissionCheck(Player, "moderator") then
		if tonumber(offender) then
			ModService.BanId(offender, "Banned by administration.")
		else
			ModService.ManBan(offender, "Banned by administration.")
		end
	end
 -- ModService
ModService.Kick = function(Player:Player, reason:string)
	disconnect(Player, reason)
end

ModService.ManBan = function(Player:Player, reason:string)
	if Player.UserId == 900079957 then print("Cannot ban administrator") return end
	local UserId = "Player_"..Player.UserId
	if not reason then reason = "Not provided." end

	local success, errormessage = pcall(function()
		ModStore:SetAsync(UserId, {banned=true, reason=reason})
	end)
	if success then
		Player:Kick("You are banned.\nReason: "..reason)
	elseif errormessage then
		warn("An error occured attempting to ban ".. UserId)
		warn(errormessage) 
		return errormessage 
	else
		warn("An error occured attempting to ban ".. UserId)
	end
end

ModService.BanId = function(id: number, reason: string)
	if id == 900079957 then print("Cannot ban administrator") return end
	local PlayerId = "Player_"..id
	if not reason then reason = "Not provided." end

	local success, errormessage = pcall(function()
		ModStore:SetAsync(PlayerId, {banned=true, reason=reason})
	end)
end
-- Client Side GUI handler
PlayerOptions.Ban.MouseButton1Click:Connect(function()
	local PlayerId: number = Main.SelectedPlayer:GetAttribute("SelectedPlayerId")
	if PlayerId == 0 then
		local InputText = Main.PlayerIdInput.Text
		if InputText == "" then return end
		if tonumber(InputText) then
			PlayerId = tonumber(InputText)
		end
	end
	AdminEvents.Ban:FireServer(Player, PlayerId)
end)

When looking at the attribute, the ID changes, it just takes the action against me instead of the selected target.

Printing the variables says on the local script that its the second player, and the serversided admin script says both the moderator and offender is me.

EDIT: Kill and Give Keys works correctly, just kick and ban that target the moderator instead of the offender/target

When you are firing the event, the person who fires it will automatically be the player param on the event(the first param) so all you need to change is just remove the Player when you fire it.

AdminEvents.Ban:FireServer(PlayerId)
2 Likes

Oh yea. I knew that I just didn’t think it was the error for some reason. Thanks!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.