Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago
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?

0
where did you set the value? jackochjulius 2 — 5y
0
Through a different script but, I also did it through the explorer and checked it was set to 1 Aerotegreat 12 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

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.

0
Okay, so how could I go about achieving this because, unfortunately I don't really understand how I do it? Thank you. Aerotegreat 12 — 5y
0
create a NumberValue in ReplicatedStorage, set it there, and make your local script access it DeceptiveCaster 3761 — 5y
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? Aerotegreat 12 — 5y
0
create a table and duplicate the value then create a debounce that checks to see if the value already exists DeceptiveCaster 3761 — 5y
View all comments (2 more)
0
What would I get it to do if the value already exists? Aerotegreat 12 — 5y
0
return end DeceptiveCaster 3761 — 5y
Ad

Answer this question