Okay, I'm still learning a lot so please dont be mad. So im trying to pass a variable from a local script with a remote event to a server script. Heres an example:
--local script: script.Parent.MouseButton1Down:Connect(function() -- this is a example so this might seem choppy local selected = "Gun1" --As an Example game.ReplicatedStorage.GetGun:FireServer(player,selected) end) --Server Script: function getgun(player,selected) gun = game.ServerStorage.Weapons:FindFirstChild(selected) gun.Parent = player.Backpack end game.ReplicatedStorage.GetGun.OnServerEvent:Connect(getgun)
Both 'player' and 'selected' are considered as the localplayer. Im trying to make 'selected' as the variable im trying to pass to my server script but its not working.
Any Help?
The function :FireServer() does not require a player argument unlike the :FireClient() function which does, therefore the corresponding event .OnServerEvent does return a player in the first argument, after this would be any thing you sent over as well. So, first let's fix your local script
--local script: script.Parent.MouseButton1Down:Connect(function() local selected = "Gun1" game.ReplicatedStorage.GetGun:FireServer(selected) --I am not including a player argument end)
Now for the script
--Server Script: function getgun(player,selected) -- OnServerEvent returns player first argument gun = game.ServerStorage.Weapons:FindFirstChild(selected) gun.Parent = player.Backpack end game.ReplicatedStorage.GetGun.OnServerEvent:Connect(getgun)
Vise versa the function :FireClient() does require a player argument and the event .OnClientEvent does not return a player