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

When the remote is fired by the text button, this error comes up, how do i fix this?

the script in sss:

 local RS = game:GetService("ReplicatedStorage")
local admincmds = RS:WaitForChild("admincmds")
local banevent = admincmds:WaitForChild("Ban")
local kickevent = admincmds:WaitForChild("Kick")
local players = game:GetService("Players")
local function kick(player, reason)
   players[player]:kick(reason)
end

kickevent.OnServerEvent:connect(kick)

the localscript in the screengui:

local adminframe = script.Parent:WaitForChild("AdminFrame")
local closebutton = adminframe:WaitForChild("closebutton")
local kickbutton = adminframe:WaitForChild("kickbutton")
local banbutton = adminframe:WaitForChild("banbutton")
local reason = adminframe:WaitForChild("reason")
local username = adminframe:WaitForChild("username")
local openbutton = script.Parent:WaitForChild("openbutton")
local RS = game:GetService("ReplicatedStorage")
local admincmds = RS:WaitForChild("admincmds")
local banevent = admincmds:WaitForChild("Ban")
local kickevent = admincmds:WaitForChild("Kick")

openbutton.MouseButton1Click:connect(function()
	adminframe.Visible = true
	openbutton.Visible = false
end)

closebutton.MouseButton1Click:connect(function()
	adminframe.Visible = false
	openbutton.Visible = true
end)

kickbutton.MouseButton1Click:connect(function()
	kickevent:FireServer(username, reason)
end)

banbutton.MouseButton1Click:connect(function()
	banevent:FireServer(username, reason)
end)

Error: ServerScriptService.Script:7: invalid argument #2 (string expected, got Instance)

2 answers

It errors because reason is an Instance, not a string. If reason is a TextBox, you need to index the Text property of reason.

2 comments

0

That, and username is an Instance

0

i only got error from players[player]:Kick(reason), how can i fix that

Update your script in ServerScriptService with this one.

local players = game:GetService("Players") or game:FindService("Players")
local RS = game:GetService("ReplicatedStorage") or game:FindService("ReplicatedStorage")

local admincmds = RS:WaitForChild("admincmds")
local banevent = admincmds:WaitForChild("Ban")
local kickevent = admincmds:WaitForChild("Kick")

kickevent.OnServerEvent:Connect(function(player_who_fired_event, player_name_provided, reason)
	for i,v in pairs(players:GetPlayers()) do -- Gets the table of all the players in the server
		if v.Name == player_name_provided.Name then -- Checks the provided player name with the names in the server to get the player instance
			v:Kick(reason) -- Kicks the player assuming the reason is a string value
		end
	end
end)

1 comment

0

players[player_name_provided] would also work just so you know..

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