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

Why does this script work in studio but not in-game?

Asked by 9 years ago

This script is supposed to give you a cup, but when you click it nothing happens. There are two scripts involved too. Here is the clicked script:

function clicked()
game.Players.LocalPlayer.PlayerGui.Giver.Disabled = false
wait(.3)
game.Players.LocalPlayer.PlayerGui.Giver.Disabled = true
end
script.Parent.MouseClick:connect(clicked)

Here is the give script:

plr = game.Players.LocalPlayer
clone = game.ServerStorage["Empty Cup"]:Clone()
clone.Parent = plr.Backpack

They are both local scripts and there are no errors. I can't find anything wrong.

1
random -1 gg Senor_Chung 210 — 9y
1
;( Senor_Chung 210 — 9y

1 answer

Log in to vote
1
Answered by 9 years ago

First off, a LocalScript cannot access ServerStorage. You'll have to move the Empty Cup into ReplicatedStorage, this way your LocalScript can access it.

Change line 2 to this-

clone = game:GetService("ReplicatedStorage")["Empty Cup"]:clone()

EDIT:

Use a GUI TextButton and place this LocalScript inside it

script.Parent.MouseButton1Down:connect(function()
clone = game:GetService("ReplicatedStorage")["Empty Cup"]:clone()
clone.Parent = game.Players.LocalPlayer.Backpack
end)
1
Thanks but it still doesn't work. Senor_Chung 210 — 9y
1
Let me edit one moment. EmergencyAlt2 50 — 9y
0
Never mind I got it. Senor_Chung 210 — 9y
Ad

Answer this question