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

How do I fix this tool cloning localscript?

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

✓ Accepted answer

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! ;)

1 comment

0

OMIGOSH THANK YOU! I just realized anything with "Server" in it should probably be avoided by client-sided things :P

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?

1 comment

0

Sorry, that didn't work ;(

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