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

My script keeps printing 0 when it checks a number value even when I set it to 1, why?

local seat = script.Parent
playerSat = false

local lastplr
seat.Changed:Connect(function(property)
    local plr = seat.Occupant
    if plr and property == "Occupant" then
        plr = game.Players:GetPlayerFromCharacter(plr.Parent)
        if plr.PlayerGui:FindFirstChild("ControlGroup") then return end
		lastplr = plr
        local c = script.ControlGroup:Clone()
        c.Parent = plr.PlayerGui
        c.DButton.Value = seat
        c.AandD.Disabled = false
		playerSat = true
		local PlayerNotch = Instance.new('NumberValue', c) --creates a part in the duped ControlGroup
		PlayerNotch.Name = "PlayerNotch"
		local PlayerNotchValue = PlayerNotch.Value--goes to the PlayerGui and finds the duped GUI called ControlGroup
		while playerSat == true do
			wait(1)
			print(PlayerNotchValue) --checks the value of playerNotch and prints it (problem where it always prints 0)
		end

I'm really unsure why this is happening, it seems like it might be checking some other number value but, it really just makes no sense to me. I created a variable for the number value that is created inside the group so surely it wouldn't be checking the wrong value?

2 comments

0

where did you set the value?

0

Through a different script but, I also did it through the explorer and checked it was set to 1

1 answer

By the looks of it, your script is local. This means that the value you set should be in a place where it can be located by the client, such as ReplicatedStorage. The client can also read Workspace. Also considering that the NumberValue should be set by the server, NOT the client, should fix your problem.

6 comments

0

Okay, so how could I go about achieving this because, unfortunately I don't really understand how I do it? Thank you.

0

create a NumberValue in ReplicatedStorage, set it there, and make your local script access it

0

Ah I see but, it is for a vehicle which would be spawned multiple times leading to the same number values int the same location. How could I get around this problem?

0

create a table and duplicate the value then create a debounce that checks to see if the value already exists

0

What would I get it to do if the value already exists?

0

return end

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