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

Why does the Changed function not actually detect the change?

Asked by 4 years ago

The script changes the BoolValue to true but the onChanged doesn't detect the change, what am I doing wrong?

local seconds = 9

while not script.Parent.Parent.spawned.Value do
    wait(1)
    seconds = seconds - 1
    script.Parent.Parent.GuiPart.BillboardGui.Frame.TextLabel.Text = seconds
    if seconds == 0 then
        script.Parent.Parent.spawned.Value = true
    end
end

local function onChanged(NewValue)
    print(NewValue) 
if script.Parent.Parent.spawned.Value == true then
        script.Parent.Parent.spawned.Value = false
        local crateModel = Instance.new("Model")
        crateModel.Parent = workspace
        local spawnBase = script.Parent
        local crates = game.ServerStorage.Crates.T4Crates:GetChildren()
        local randomCrate = crates[math.random(1, #crates)]
        local pos = Vector3.new(math.random(-spawnBase.Size.x/2, spawnBase.Size.x/2), spawnBase.Size.y/2, Vector3.new(spawnBase.Size.Y+10), math.random(-spawnBase.Size.z/2,spawnBase.Size.z/2))
        local rotation = randomCrate:SetPrimaryPartCFrame(spawnBase.CFrame * CFrame.new(pos))
        randomCrate.Handle.BodyForce = Vector3.new(0, randomCrate.Handle:GetMass()* 196.2, 0)           
    end
end
script.Parent.Parent.spawned.Changed:Connect(onChanged)
0
Try using GetPropertyChangedSignal("WhateverProperty"). It fires whenever the property of the object changes. for example: script.Parent.Bool:GetPropertyChangedSignal("Value"):Connect(function(). It'll fire when the "value" property of the object bool changes DizzyGuy70 38 — 4y
0
Still doesn't work @Dizzy tibiscus 0 — 4y
0
try using a coroutine youtubemasterWOW 2741 — 4y
0
The argument passed into onChanged is supposed to be the name of the property, not the value of the property. (https://developer.roblox.com/en-us/api-reference/event/Instance/Changed) y3_th 176 — 4y

Answer this question