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

I made this ban GUI and it's not working! Can someone please help me?

So, I made this ban GUI script but when I run it, it says in the output that the player does not exist.

Here's the local script in the GUI.

local Username = script.Parent.Parent.Username.TextBox.Text
local Reason = script.Parent.Parent.Reason.TextBox.Text
local Evidence = script.Parent.Parent.Evidence.TextBox.Text

script.Parent.MouseButton1Click:Connect(function()
	print("Button was pressed!")
	if game.Players:FindFirstChild(Username) then
		print("Succesfully got a player!")
		game.ReplicatedStorage.ModEvents.BanPlayer:FireServer(Username, Reason)
	else
		print("Player does not exist!")
	end
end)

Here's the output when I press it:

https://prnt.sc/trdnbd

And here's the server script that gets the remote event:

game.ReplicatedStorage.ModEvents.BanPlayer.OnServerEvent:Connect(function(player, Username, Reason)
	game.Players:FindFirstChild(Username):Kick("\nYou have been banned for:\n"..Reason.."\n By: "..player.Name.. " | "..player.UserId)
	game.Players:FindFirstChild(Username).modstats.Banned.Value = true
	if game.Players:FindFirstChild(Username).modstats.Banned.Value == true then
		game.Players:FindFirstChild(Username):Kick("\nYou are for:\n"..Reason.."\n By: "..player.Name.. " | "..player.UserId)
	end
end)

Can someone help?

1 answer

✓ Accepted answer

You'll have to put the variables inside of the function. As soon as the game starts, the variables will be defined, but later in the game, you type in the text boxes and click the button, the variables won't change.

(probably makes no sense, just try this script)

script.Parent.MouseButton1Click:Connect(function()
local Username = script.Parent.Parent.Username.TextBox.Text
local Reason = script.Parent.Parent.Reason.TextBox.Text
local Evidence = script.Parent.Parent.Evidence.TextBox.Text
    print("Button was pressed!")
    if game.Players:FindFirstChild(Username) then
        print("Succesfully got a player!")
        game.ReplicatedStorage.ModEvents.BanPlayer:FireServer(Username, Reason)
    else
        print("Player does not exist!")
    end
end)

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