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

How do I index a number to a numbervalue's Value without studio "erroring" for seemingly no reason?

Asked by 3 years ago

Recently, I've been trying to use string/bool/number values in order to facilitate communication between scripts. I store those values inside ServerStorage. However, for some reason there is a numbervalue I am unable to change due to a weird error that keeps popping up in my output.

The script I'm using is rather long, so I'll only show a sniplet of it.

local SS = game:GetService("ServerStorage")
local RS = game:GetService("ReplicatedStorage")
local Bomb1 = RS:FindFirstChild("Bomb1")
local bCount = SS:FindFirstChild("bCount")
local pitch = SS:FindFirstChild("pitch")
local bombRate = SS:FindFirstChild("bombRate")

while true do
    if bCount.Value >= 5 then
    Bomb1.mainpart.Color = Color3.fromRGB(200, 255, 19)
    pitch.Value = 0.9
    bombRate.Value = 3
        wait(0.1)
        end
end

bCount, pitch and bombRate are all numbervalues, but in this script I only want to change pitch and bombRate's values.

This is what comes out of the output when bCount.Value >= 5 :

ServerScriptService.bombModifierScript:12: attempt to index number with 'Value' - Server - bombModifierScript:12

What's really grinding my gears is how it errors at the 12nd line, which isn't even the pitch value's line, it's the bombRate's value line. I don't understand how the script manages to change the value of pitch, yet it errors at bombRate.

There is another script in which I reference bombRate, but I'm 100% sure it has no influence on the script error behavior, though if you'd like I can show you the script if you need more clues.

Any form of help is appreciated

2 answers

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

TRY THIS

local SS = game:GetService("ServerStorage")
local RS = game:GetService("ReplicatedStorage")
local Bomb1 = RS:FindFirstChild("Bomb1")
local bCount = SS:FindFirstChild("bCount")
local pitch = SS:FindFirstChild("pitch")
local bombRate = SS:FindFirstChild("bombRate")

coroutine.resume(coroutine.create(function() -- While True Do Would Loop Forever And The Rest Of The Code Would Never Run!
while true do
    if bCount.Value >= 5 then
    Bomb1.mainpart.Color = Color3.fromRGB(200, 255, 19)
    pitch.Value = 0.9
    bombRate.Value = 3
end
end))

if bCount.Value >= 15 then
    Bomb1.mainpart.Color = Color3.fromRGB(255, 200, 0)
    Bomb1.mainpart.Material = Enum.Material.Concrete
    pitch.Value = 0.8
    bombRate.Value = 2.5
end

if bCount.Value >= 30 then
    Bomb1.mainpart.Color = Color3.fromRGB(255, 79, 10)
    pitch.Value = 0.7
    bombRate.Value = 2
end

if bCount.Value >= 45 then
    Bomb1.mainpart.Color = Color3.fromRGB(255, 5, 92)
    Bomb1.mainpart.Material = Enum.Material.Pebble
    pitch.Value = 1.2
    bombRate.Value = 0.75
end

if bCount.Value >= 125 then
    Bomb1.mainpart.Color = Color3.fromRGB(200, 0, 255)
    Bomb1.mainpart.Material = Enum.Material.Slate
    pitch.Value = 0.5
    bombRate.Value = 1.5
end

if bCount.Value >= 200 then
    Bomb1.mainpart.Color = Color3.fromRGB(3, 209, 255)
    Bomb1.mainpart.Material = Enum.Material.Neon
    pitch.Value = 1.2
    bombRate = 0.75
end

if bCount.Value < 5 then
    Bomb1.mainpart.Color = Color3.fromRGB(75,151,75)
    Bomb1.mainpart.Material = Enum.Material.Plastic
    pitch.Value = 1
        bombRate = 5
end
wait(0.1)
end
0
I checked in the explorer with "bombRate" as keyword and the only thing that came up was my number value in the server storage. I'll post more of the code Auterus 0 — 3y
0
@Auterus hey I just fixed it! Sorry for the late response :/ lsltReaIIyYou 64 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

As requested, here is some more of the code to help you out The first block of code is the full script that includes the sniplet I made in the original post

local SS = game:GetService("ServerStorage")
local RS = game:GetService("ReplicatedStorage")
local Bomb1 = RS:FindFirstChild("Bomb1")
local bCount = SS:FindFirstChild("bCount")
local pitch = SS:FindFirstChild("pitch")
local bombRate = SS:FindFirstChild("bombRate")

while true do
    if bCount.Value >= 5 then
    Bomb1.mainpart.Color = Color3.fromRGB(200, 255, 19)
    pitch.Value = 0.9
    bombRate.Value = 3
end

if bCount.Value >= 15 then
    Bomb1.mainpart.Color = Color3.fromRGB(255, 200, 0)
    Bomb1.mainpart.Material = Enum.Material.Concrete
    pitch.Value = 0.8
    bombRate.Value = 2.5
end

if bCount.Value >= 30 then
    Bomb1.mainpart.Color = Color3.fromRGB(255, 79, 10)
    pitch.Value = 0.7
    bombRate.Value = 2
end

if bCount.Value >= 45 then
    Bomb1.mainpart.Color = Color3.fromRGB(255, 5, 92)
    Bomb1.mainpart.Material = Enum.Material.Pebble
    pitch.Value = 1.2
    bombRate.Value = 0.75
end

if bCount.Value >= 125 then
    Bomb1.mainpart.Color = Color3.fromRGB(200, 0, 255)
    Bomb1.mainpart.Material = Enum.Material.Slate
    pitch.Value = 0.5
    bombRate.Value = 1.5
end

if bCount.Value >= 200 then
    Bomb1.mainpart.Color = Color3.fromRGB(3, 209, 255)
    Bomb1.mainpart.Material = Enum.Material.Neon
    pitch.Value = 1.2
    bombRate = 0.75
end

if bCount.Value < 5 then
    Bomb1.mainpart.Color = Color3.fromRGB(75,151,75)
    Bomb1.mainpart.Material = Enum.Material.Plastic
    pitch.Value = 1
        bombRate = 5
end
wait(0.1)
end

The second block of code simply represents the other instance where I mention bombRate, though this may not be particularly useful:

local RS = game:GetService("ReplicatedStorage")
local SS = game:GetService("ServerStorage")
local Bomb1 = RS.Bomb1
local bCount = SS:FindFirstChild("bCount")
local sign = game.Workspace.Sign
local teleport = game.Workspace.teleport
local vpName = SS:FindFirstChild("playerName")
local currentGame = SS:FindFirstChild("currentGame")
local cooldown = 10
local bombRate = SS:FindFirstChild("bombRate")
sign.gui.label.Text = "STEP IN NOW AND/OR DIE"


local function bombSpawn(hit)
    local humanoid = hit.Parent:FindFirstChild("Humanoid")
    if humanoid and currentGame.Value == false and humanoid.Health > 0 then
            hit.Parent:FindFirstChild("HumanoidRootPart").CFrame = CFrame.new(-6,8.6,28)
            vpName.Value = hit.Parent.Name
            currentGame.Value = true
            while humanoid and humanoid.Health > 0 do
                local x = math.random(-28.5, 13.5)
                local z = math.random(-8.5, 33.5)
                local cBomb1 = Bomb1:Clone()
                cBomb1:SetPrimaryPartCFrame(CFrame.new(x, 33.5, z))
                cBomb1.Parent = game.Workspace
                bCount.Value += 1
                sign.gui.label.Text = "Current score: ".. bCount.Value.. ", achieved by ".. vpName.Value
                wait(bombRate.Value)
            end
        end
    if currentGame.Value == true and humanoid == nil or humanoid.Health <= 0 then
        while cooldown > 0 do
            sign.gui.label.Text = vpName.Value.." Has died! Score: "..bCount.Value.." ! New game in "..cooldown.." seconds!"
            cooldown -= 1
            wait(1)
        end
        cooldown = 10
        bCount.Value = 0
        sign.gui.label.Text = "STEP IN NOW AND/OR DIE"
        currentGame.Value = false
    end
    end



teleport.Touched:Connect(bombSpawn)

Answer this question