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

Why is my cloning a tool into the the player's inventory script only working in studio?

I have a script that works in studio, but not in the actual game. What is wrong? It isn't cloning my milk tool into the player's inventory.

local CupTool = game.ServerStorage.Milk

script.Parent.Touched:connect(function(hit) 
	if hit.Parent.Name == "Empty Cup" then
		hit.Parent:Destroy()
        CupTool:Clone().Parent = game.Players.LocalPlayer.Backpack
        wait()
    end
end

2 answers

Is that a local script? If so, local scripts can not access ServerStorage. They can in studio, but not in the full game. You should put the cup tool in ReplicatedStorage instead.

It may because you're using a local script, if it is then I have a few changes:

local CupTool = game.ServerStorage.Milk
script.Parent.Touched:connect(function(hit)
	if hit.Parent.Name == "Empty Cup" then
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		hit.Parent:Destroy()
		CupTool:Clone().Parent = player.Backpack
	end
end) -- Forgot your closed bracket.

1 comment

0

It is not a local script.

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