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

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

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.

2 comments

1

random -1 gg

1

;(

1 answer

✓ Accepted answer

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)

3 comments

1

Thanks but it still doesn't work.

1

Let me edit one moment.

0

Never mind I got it.

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