You would have to use the local script to fire a RemoteEvent or RemoteFunction and pick up the info with remoteevent.OnServerEvent or like remotefunction.OnServerInvoke
If the script under the gui button is not a local script, change it to a local script. Insert a remote event into replicated storage and insert a script into ServerScriptService.
-- Local script
script.Parent.MouseButton1Click:Connect(function()
game.ReplicatedStorage.RemoteEventName:FireServer()
end)
--Server Script
game.ReplicatedStorage.RemoteEventName.OnServerEvent:Connect(function(plr)
-- Insert your randomiser and team change code here
end)
You can not get the player who clicked via server script if it is in a text button. You can only do this in a ClickDetector, players.PlayerAdded/ChildAdded, or in a Touch event. The best you can do is use a local script which LIKELY will not work as it will replicate to the client and not the server! So the best you can do is use remote events to send data/arguments through a local script to a server script with remote:FireServer() and OnServerEvent. You can learn how to do this here:
The error was in the script in this location. You already know that.
Script:7:
The error was on the 7th line, right here:
if Ran == 1 and plr.Team ~= game.Teams.Judges and game.Workspace.GlobalValues.Judges.Value <= 3 and plr.leaderstats.Talent.Value >= 10 then
attempt to index nil with ‘Team’
Indexing something in Lua is trying to access a table or object’s properties. Like script.Parent, in which you index Script with Parent.
The error is telling you that you’re trying to get nil.Team.
On that line, there is plr.Team. This is what is causing the error. plr is nil.
Button.MouseButton1Click:Connect(function(plr) -- there is no plr!
MouseButton1Click is not supposed to give anything to the function.
The fix is to find the player in some other way.
In a LocalScript, you can write
-- LocalScript
local plr = game.Players.LocalPlayer
-- Script
local plr = script.Parent.Parent.Parent.Parent.Parent.Parent
(The Script example only works as-is if the Script is in the GUI)