So I'm making a TextButton, and inside it I added a LocalScript that when the button is clicked, I want it to give a player the item "Latte". It works in Roblox Studio, but not in the actual game! Here it is:
1 | local player = game.Players.LocalPlayer |
2 |
3 | function onClicked() |
4 | game.ServerStorage.Latte:clone().Parent = player.Backpack |
5 | end |
6 |
7 | script.Parent.MouseButton 1 Down:connect(onClicked) |
Does anybody know what's wrong with my script? If so, please help!
It's probably because the Tool is in the ServerStorage, meaning it is accessible only from Server Scripts, not Local Scripts. Try moving the "Latte" to ReplicatedStorage, it is used for both Server Scripts and Local Scripts.
1 | local player = game.Players.LocalPlayer |
2 |
3 | function onClicked() |
4 | game.ReplicatedStorage.Latte:clone().Parent = player.Backpack |
5 | end |
6 |
7 | script.Parent.MouseButton 1 Down:connect(onClicked) |
Hope it helps! ;)
1 | local player = game.Players.LocalPlayer |
2 | local serverstorage = game:GetService( "ServerStorage" ) |
3 |
4 | function onClicked() |
5 | serverstorage.Latte:Clone().Parent = player.Backpack |
6 | end |
7 |
8 | script.Parent.MouseButton 1 Down:connect(onClicked) |
idk but maybe this will work?