Script not refreshing

  1. What do I want to achieve? A responding script

  2. What is the issue? So i made a point system and whenever it reached 5 it locks you in 5 and u have to reset it through a part. the storage thingy works fine BUT after i reset it is not giving me points.

  3. **What solutions have you tried so far?**I tried looking at the devhub, no solution : (

-- The point gaining script
script.GetStrength.OnServerEvent:Connect(function (player)	
	for i, item in ipairs(player.Ownedtools:GetChildren()) do
		if item:IsA("Tool") then
			local amount = item.Strength.Value
			if player.leaderstats.Strength.Value >= tonumber(player.Storage.Value) then
				player.leaderstats.Strength.Value = tonumber(player.Storage.Value)
				script.Disabled = true
				wait(1)
			else if player.leaderstats.Strength.Value < tonumber(player.Storage.Value) then
					script.Disabled = false
					player.leaderstats.Strength.Value = player.leaderstats.Strength.Value + amount
				end
				
			end
		end
		
	end
	
end)
local Part= script.Parent
Part.Touched:Connect(function (Hit)
	local H= Hit.Parent:FindFirstChild("Humanoid")
	if H then
		local player= game.Players:GetPlayerFromCharacter(Hit.Parent)
		if player then
			local leaderstats= player:WaitForChild("leaderstats")
			local Currency= leaderstats.Coins
			local Selling= leaderstats.Strength
			if Selling.Value >= 0 then
				Currency.Value =Currency.Value + Selling.Value*9999999
				Selling.Value= 0
				
			end
		end
	end
end)

This is an experiment so yes Also help me ASAP please and thank you!

The script won’t run if you disable it unless you enable it in another script but not in the script you want to disable, you should use break to stop a for loop.

It shows me an error like this: Workspace.another:3: attempt to index nil with ‘leaderstats’

code:

local plr = game.Players.LocalPlayer

if plr.leaderstats.Strength.Value < plr.Storage.Value then
	script.Parent.MainEvents.Disabled = false

end
local plr = game.Players.LocalPlayer
local leaderstats = plr:WaitForChild("leaderstats")

if leaderstats.Strength.Value < plr.Storage.Value then
	script.Parent.MainEvents.Disabled = false

end

Could you explain again what you want and what issue you have. Not to be rude or anything but it is not really that clear.

Workspace.another:2: attempt to index nil with ‘WaitForChild’

there is an error

so lets say u have 5 points, ok? after 5 points u cant gain points unless u reset. But after resetting it does not give me points

Is this the script that should allow u to have more points/enables the script when u reset?

no , this is the script which enables the other script:

local plr = game.Players.LocalPlayer
local leaderstats = plr:WaitForChild("leaderstats")

if leaderstats.Strength.Value < plr.Storage.Value then
	script.Parent.MainEvents.Disabled = false

end

What type of script is it? If it is a server script then your issue is there is nothing making the code run.

In server scripts you have to have some type of event if you want the code to run cuz the server script only runs once when the server starts.

i have a remote event to fire the code.

Hello sorry for the late response but it shows me this error:
Workspace.bro:2: attempt to index nil with ‘leaderstats’

my script:

local player = game:GetService("Players").LocalPlayer
if player.leaderstats.Strength.Value >= tonumber(player.Storage.Value) then
	player.leaderstats.Strength.Value = tonumber(player.Storage.Value)
	script.Parent.MainEvents.Disabled = true
elseif player.leaderstats.Strength.Value < tonumber(player.Storage.Value) then
	script.Parent.MainEvents.Disabled = false
end

i am not to sure if this really works:

local plr = game.Players.LocalPlayer
local leaderstats = plr:WaitForChild("leaderstats")

if leaderstats.Strength.Value < plr.Storage.Value then
script.Parent.MainEvents.enabled = false

well, i am not a good scripter, so i don’t know if it’s right.

Hello, thank you for trying to help. However this does not work

atleast, i tried. bruh, even i’m not good at scripting.

thank you for helping me but still it doesn’t work

and if anyone is wondering this script is a normal script please help me im stuck