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

How do I fix this number randomizing script?

Asked by 8 years ago
game:GetService('Players').PlayerAdded:connect(function(player)
    player.CharacterAdded:connect(function(character)
        character:WaitForChild("Humanoid").Died:connect(function()
            local value = script.Parent.Value
            value.Value = math.random(1,10) 
            if value == 6 then
                script.Parent.Parent.ScreenGui.NewItem.GreenSaber.Visible = true
            end
        end)
    end)
end)

I confused myself and all I want to do is... 1.) When a player dies, randomize a number 1-10 2.) If it is equal to 6, make a GUI visible.

1 answer

Log in to vote
2
Answered by 8 years ago

You've got a bit mixed up with your "value" variables.

On line 4, you declare "value" as script.Parent.Value, I think that this is an IntValue? Meaning that the stored variable will be an integer.

You then try to change the value of the integer variable, which of course, there is none.

You will want:

game:GetService('Players').PlayerAdded:connect(function(player)
    player.CharacterAdded:connect(function(character)
        character:WaitForChild("Humanoid").Died:connect(function()
            local value = script.Parent --Set the variable to the IntValue instance
            value.Value = math.random(1,10)  --Set the IntValue's value to the rgn
            if value.Value == 6 then --Check the value
                script.Parent.Parent.ScreenGui.NewItem.GreenSaber.Visible = true
            end
        end)
    end)
end)

Unless you need the IntValue's value, I'd recommend using the following script and assigning a local variable instead:

game:GetService('Players').PlayerAdded:connect(function(player)
    player.CharacterAdded:connect(function(character)
        character:WaitForChild("Humanoid").Died:connect(function()
            local value = math.random(1,10)  --Set the variable to the rgn
            if value == 6 then --Check the variable
                script.Parent.Parent.ScreenGui.NewItem.GreenSaber.Visible = true
            end
        end)
    end)
end)
Ad

Answer this question