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

Works in studio but not in Play Online?

Whenever I run this in studio everything works perfect and resets the values, but if I run it by going to the place and clicking Play. It doesn't reset any values.

reset.MouseButton1Down:connect(function()
	for i,v in pairs(game.Players:GetPlayers()) do
		for k,val in pairs(v.leaderstats:GetChildren()) do
			if val:IsA("IntValue") then
				val.Value=0
			elseif val:IsA("StringValue") and val.Name=="Promotion" then
				val.Value="No"
			end
		end
	end
end)

Part of a larger code.

1 answer

In the code you provided, you didn't define 'reset' on line 1. It's nil. Unless you meant to make a connection statement, in that case you would have to do..

function reset()
	for i,v in pairs(game.Players:GetPlayers()) do
		for k,val in pairs(v.leaderstats:GetChildren()) do
			if val:IsA("IntValue") then
				val.Value=0
			elseif val:IsA("StringValue") and val.Name=="Promotion" then
				val.Value="No"
			end
		end
	end
end

script.Parent.MouseButton1Down:connect(reset)

But ultimately, we can't help you unless you supply the whole script, and output if there is any.

Make sure this is a localscript.

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