Script not recognising a value

Note!: the scripts used to work before, they suddenly don’t work anymore, and no I haven’t changed anything about them…

This is one of the script where I need the value.

local remote = game.ReplicatedStorage.RemoteEvent

remote.OnServerEvent:Connect(function(Player)
	Player.leaderstats.Money.Value -= 80
	local pl = game.ReplicatedStorage.Players:WaitForChild(Player.Name) -- These parts
	local chad = pl:FindFirstChild("Chad", true) --
	chad:FindFirstChild("Health", true).Value = 100 -- the value is not changing.
end)

and no, there’s no error. Everything else works, so the money’s value is getting decreased.

1 Like

Try this:

--//Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")

--//Variables
local remote = ReplicatedStorage.RemoteEvent

--//Functions
remote.OnServerEvent:Connect(function(player)
	player.leaderstats.Money.Value -= 80
	
	local pl = ReplicatedStorage.Players:FindFirstChild(player.Name)
	local chad = pl and pl:FindFirstChild("Chad")
	local health = chad and chad:FindFirstChild("Health")
	
	print(health and "Successful" or "Unsuccessful")
	
	if health then
		health.Value = 100
	end
end)

It prints successful, but nothing happens, the value is still the same

Do you have any other script that does something with Chad?

Yes I have many other scripts that use chad, but keep this in mind, these scripts used to work, somehow when I got back today, it stopped working.

That’s weird… Try restarting roblox studio. Sometimes for me stuff doesn’t work like sound not playing from a script, until I restart

I have already, multiple times even.

local remote = game.ReplicatedStorage.RemoteEvent

remote.OnServerEvent:Connect(function(Player)
	Player.leaderstats.Money.Value -= 80
	local pl = game.ReplicatedStorage.Players:WaitForChild(Player.Name) -- These parts
	local chad = pl:FindFirstChild("Chad", true) --
	local health = chad:FindFirstChild("Health", true)
    print('Previous value:'..health.Value)
    health.Value = 100
    print('New value:'..health.Value)
    while task.wait(1) do
        print(health.Value)
    end
end)

try this to monitor what happens after you change the value. I’m wondering if maybe it is being changed by something else

Doesn’t work.

You must be changing the health value to 78 using a local script right?

oh my god, yes it’s done in a localscript…

That’s your problem. Changing the value with a local script wont replicate that value to the server. So to the server the health value has never changed from 100. Fire a remote event from that local script to get the server to change the value whenever you want to raise/lower it

Hm, I’ve changed it, but it still won’t work

Nevermind it works, I made a small mistake haha!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.