Still have questions? Join our Discord server and get real time help.
Log in to vote

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

Asked by 5 months ago

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.ServerStorage.F3X.Parent = game.Workspace
    game.Workspace.F3X.Parent = game.Players.PlayerName.StarterGear

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

Any help would be appreciated, thanks in advance.

Btw, for line 5 I meant Backpack. ExtremeRisk 9 — 5mo
Any errors? Rheines 585 — 5mo

1 answer

Log in to vote
Answered by
Rheines 585 Moderation Voter
5 months ago
Edited 5 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.
    --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

Answer this question