I am making it, so that when the player is a spy or a soldier, they get a tool. But they aren’t getting the tool with no error.
Local script:
local remoteEvent = game.ReplicatedStorage:WaitForChild("GUIEvent")
local WeaponEvent = game.ReplicatedStorage:WaitForChild("WeaponEvent")
local Player = game.Players.LocalPlayer
remoteEvent.OnClientEvent:Connect(function(selectedRole)
script.Parent.Visible = true
if selectedRole == "Scientist" then
script.Parent.TextSize = 50
script.Parent.Text = "Scientist, stick with soldiers!"
wait(4)
script.Parent.Parent.Visible = false
elseif selectedRole == "Soldier" then
WeaponEvent:FireServer(Player,selectedRole)
script.Parent.TextSize = 50
script.Parent.Text = "Soldier, protect scientists against the spy!"
wait(4)
script.Parent.Parent.Visible = false
elseif selectedRole == "Spy" then
WeaponEvent:FireServer(Player,selectedRole)
script.Parent.TextSize = 50
script.Parent.Text = "Spy, kill soldiers and scientists, and gather data!"
wait(4)
script.Parent.Visible = false
end
end)
Script:
local WeaponEvent = game.ReplicatedStorage:WaitForChild("WeaponEvent")
WeaponEvent.OnServerEvent:Connect(function(Player, selectedRole)
if selectedRole == "Soldier" then
local tool = game.ReplicatedStorage.Pistol:Clone()
tool.Parent = Player.Backpack
script.Parent.Parent.Visible = false
elseif selectedRole == "Spy" then
local tool2 = game.ReplicatedStorage.ClassicSword:Clone()
tool2.Parent = Player.Backpack
end
end)
In firing a server you don’t need to add player as a parameter because when you connect a RemoteEvent that is fired by the client to a function the first argument is already the player even though you didn’t set it as a parameter when you fired the server.
In this code:
WeaponEvent:FireServer(Player,selectedRole)
it would pass 3 parameters. (The main player, an argument that isn’t supposed to exist, and the selected role)
instead do this:
WeaponEvent:FireServer(selectedRole)
in this line of code it would only pass 2 parameters which is the main player and the selected role.
Separate note but I highly recommend divorcing these systems. Exploiters can just fire your remotes and receive all the tools given that there’s no security and you’re letting the client be authoritative of deciding what role it wants to be. Not only that, but considering the content of the script, I can already tell you have a regular script and a RemoteEvent in a Gui which is improper.
There should be no remotes involved at any step here. Your current workflow incurs unnecessary network use in sending data over and lack of security on the remote. Instead, the server should be responsible for handling tool distribution based on how roles are chosen. It should then fire a RemoteEvent in ReplicatedStorage so for the client, only to display what role the server selected for them. It’s already clear that you’ll know what role a player has from the server given the code.