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

How do I fix this tool cloning localscript?

Asked by
itsJooJoo 195
8 years ago

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:

local player = game.Players.LocalPlayer

function onClicked()
    game.ServerStorage.Latte:clone().Parent = player.Backpack
end

script.Parent.MouseButton1Down:connect(onClicked)

Does anybody know what's wrong with my script? If so, please help!

2 answers

Log in to vote
0
Answered by 8 years ago

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.

local player = game.Players.LocalPlayer

function onClicked()
    game.ReplicatedStorage.Latte:clone().Parent = player.Backpack
end

script.Parent.MouseButton1Down:connect(onClicked)

Hope it helps! ;)

0
OMIGOSH THANK YOU! I just realized anything with "Server" in it should probably be avoided by client-sided things :P itsJooJoo 195 — 8y
Ad
Log in to vote
0
Answered by 8 years ago
local player = game.Players.LocalPlayer
local serverstorage = game:GetService("ServerStorage")

function onClicked()
    serverstorage.Latte:Clone().Parent = player.Backpack
end

script.Parent.MouseButton1Down:connect(onClicked)

idk but maybe this will work?

0
Sorry, that didn't work ;( itsJooJoo 195 — 8y

Answer this question