Hi. Was testing a Gui vending machine script today. It however, only works in studio. When I try to test it in ROBLOX, the TextButton won't give the tool. Here is the script:
tool = game.ServerStorage.Aquafina script.Parent.MouseButton1Down:connect(function() local thetool = game.Players.LocalPlayer.Backpack:FindFirstChild("Aquafina") if thetool then print "ToolGiven" else local g = tool:Clone() g.Parent = game.Players.LocalPlayer.Backpack end end)
Best Regards, Boomer
This is because the client/player doesn't have access to the "ServerStorage" service, meaning your code won't work.
Please do this server-sided.
Here is the code on how to give a tool to a player, server-sided. You need to use Remote Events/Functions to do this
local ServerStorage = game:GetService("ServerStorage"); local Tool = ServerStorage:FindFirstChild("Aquafina") --Function that's being run when certain event has happened.. --Assuming Player is defined if Player.Backpack:FindFirstChild("Aquafina") ~= nil then print("Already given the tool to this player") else local cloneTool = Tool:Clone() cloneTool.Parent = Player.Backpack end
That's just one way to do it, please note there's no fail-safety