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

How do I make this script work in a localserver?

It wont give me gems after i touch it

local deb = false
script.Parent.Touched:connect(function(hit)
if game.Players.LocalPlayer.Maxgems.Max.Value - game.Players.LocalPlayer.leaderstats.Gem.Value > 0 then 
if hit.Parent:FindFirstChild("Humanoid") then
if deb == false then
    for _,Player in pairs(game.Players:GetPlayers()) do
        if Player:FindFirstChild("leaderstats") then
            Player.leaderstats.Gem.Value = Player.leaderstats.Gem.Value +1
workspace.CollectSound:Play()
               script.Parent:Destroy()
	if game.Players.LocalPlayer.leaderstats.Gem.Value > game.Players.LocalPlayer.Maxgems.Max.Value then
	 game.Players.LocalPlayer.leaderstats.Gem.Value = 10
	end
					end
				end
			end
        end
    end
deb = true
wait(0.1)
deb = false
end)

No output errors

3 comments

0

Please use indentation in your scripts.

0

ffs

0

create a variable "local LocalPlayer = game:GetService("Players"):FindFirstChild(hit.Parent.Name)" and use it to get the LocalPlayer. LocalPlayer does not work in a server-script

1 answer

You destroyed the parent of your script thus destroying your script. EDIT: Move your script somewhere else other than the parent of the current script.

4 comments

0

this did not hep

0

Edited.

0

If you accept this answer please click the "Accept Answer" button.

0

i tried this, and it doesnt work

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