Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How would I give someone a tool through a gui?

So I'm making a check out station where if you click a GUI, it will give you a tool. I don't know how to access a tool and put it in a person's inventory. I would love it if someone could help me with this I thought this would work but it apparently doesn't.

local tool = game.ServerStorage.Card
local klone = tool:clone()
script.Parent.MouseButton1Click:Connect (function(plr)
if klone.Parent ~= plr.Backpack then
klone.Parent = plr.Backpack
else
end
end)

2 answers

Maybe this will work for you

First add a serverscript to ServerScriptService.

Second add a RemoteEvent to ReplicatedStorage.

And this is the content in the ServerScript:

local tool = game.ServerStorage.Card
local klone = tool:clone()
local remote = game.ReplicatedStorage.RemoteEvent
remote.OnServerEvent:Connect(function() --if the event fired, it will do the stuff in the function
if klone.Parent ~= plr.Backpack then
klone.Parent = plr.Backpack
end
end)

And the local script in the textbutton should be like this:

local remote = game.ReplicatedStorage.RemoteEvent

script.Parent.MouseButton1Click:Connect(function(plr)

remote:FireServer() -- fire so the server script would run

end)

That's all what i know.

This discussion is preserved as it was. New answers, comments, and votes are closed.