Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
Jexpler 63
8 years ago
Edited 8 years ago

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

Log in to vote
0
Answered by
Xiousa 156
8 years ago

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.

Ad
Log in to vote
0
Answered by
Master_JJ 229 Moderation Voter
8 years ago
Edited 8 years ago

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.
0
It is not a local script. Jexpler 63 — 8y

Answer this question