Still have questions? Join our Discord server and get real time help.
0

# Is it possible to make this give the tool to the Player who triggered the script?

Basically, I'm messing around with my new GUI I made. When clicked it Fires a RemoteEvent called 'give_event' when triggered, It gives the tools to me. But the problem is, I want it to be given to the person who clicked... I don't want to modify the ServerScript's name Here is what I got:

game.ReplicatedStorage.give_event.OnServerEvent:Connect(function()
game.ServerStorage:FindFirstChild("F3X")
game.ServerStorage.F3X.Parent = game.Workspace
wait(0.1)
game.Workspace.F3X.Parent = game.Players.PlayerName.StarterGear
end)


(Yes that's the ServerScript triggered by the RemoteEvent.)

Any help would be appreciated, thanks in advance.

0
Btw, for line 5 I meant Backpack. ExtremeRisk 14 — 2mo
0
Any errors? Rheines 552 — 2mo

0
Rheines 552
2 months ago
Edited 2 months ago

OnServerEvent has a default player argument, and we can use this to modify the player's backpack. Also, you need to clone the tool and parent it, as only parenting it to somewhere will only move the tool to the player's backpack and will only work once.

FindFirstChild returns nilif the tool is not found in the ServerStorage, and this may happen when the script runs first before the tool has loaded. If you are really sure that the tool exists in ServerStorage, use WaitForChild instead, and the script will yield until the tool has loaded.

--Get the player who fired the RemoteEvent using the default player argument.
game.ReplicatedStorage.give_event.OnServerEvent:Connect(function(player)
--Clone the tool from server storage after waiting for it to load.
local tool = game.ServerStorage:WaitForChild("F3X"):Clone()
--Parent it to the player's backpack.
tool.Parent = player.Backpack
end)