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

How do I fix this tool-giving script, which only works in studio, it doesn't work in game?

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

1 comment

0

How would the server know what "LocalPlayer" is?

1 answer

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

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