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

Script only works on studio?

script.Parent.MouseButton1Click:connect(function()
	if game.Players.LocalPlayer.leaderstats.Money.Value == 650 or game.Players.LocalPlayer.leaderstats.Money.Value > 650 then
		if game.Players.LocalPlayer.Backpack:FindFirstChild("Heal Spell") == nil then
			
		game.Players.LocalPlayer.leaderstats.Money.Value = game.Players.LocalPlayer.leaderstats.Money.Value - 650
		local c = game.ServerStorage["Heal Spell"]:Clone()
		c.Parent = game.Players.LocalPlayer.Backpack
		end
		end
end)

This script is supposed to clone you a heal spell if you have enough money, and if you don't already own it. The problem is it only works in studio. This is a localscript inside a Textbutton.

1 comment

0

Try putting this in replicated storage, then cloning it from there.

2 answers

LocalScripts don't have access to ServerStorage -- that's storage for the server. Use ReplicatedStorage for things that clients need access to.

I would recommend storing game.Players.LocalPlayer as a variable, since you use it so many times!


Also, remember that changing leaderstats from a LocalScript won't completely work with FilteringEnabled.

In tandem with what BlueTaslem said, you can't modify objects in ServerStorage from the client. You can try using remote events / functions to modify / access objects stored on the server.

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