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

[RESOLVED] GetPropertyChangedSignal and/or Changed not working?

Asked by 5 years ago
Edited 5 years ago

I'm trying to script a block that destroys itself after the IntValue inside of it reaches the number 2. The following code is in a Script which is placed in the IntValue. I included the wait statement in case the problem was just that something didn't load, but that didn't fix it. There are no error messages. Nothing happens in output, so the function just isn't running. The block doesn't destroy itself even when the IntValue reaches 2.

block = script.Parent.Parent
dmg = script.Parent

repeat wait() until dmg ~= nil

dmg:GetPropertyChangedSignal("Value"):Connect(function()
    print("changed")
    if dmg.Value >= 2 then
        block:Destroy()
        print("destroy")
    else if dmg.Value < 2 then
        print("safe")
    end
    end
end)

Any help is super appreciated.

0
Is there a chance that your repeat wait() is just going on a forever loop? crywink 419 — 5y
0
It's possible. The script doesn't work either way. Flannelling 4 — 5y
0
put a print outside of the function and test if it works awesomeipod 607 — 5y
0
Anything I print outside of the function works just fine. It's just that the function itself won't go. Flannelling 4 — 5y
View all comments (2 more)
0
then the GetPropertyChangedSignal event isn't firing. Is there another script that changes the value? local script or server script? awesomeipod 607 — 5y
0
Yes, a tool changes the value (I click on the block with the tool and the IntValue changes). It's a local script for the tool. Is that the issue? Flannelling 4 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago
  1. Use local variables.

  2. Using a repeat loop is absolutely pointless. The function fires whenever the value is changed. (Also, the script is just stuck at the loop.)

Fixed script:

local block = script.Parent.Parent
local dmg = script.Parent

dmg:GetPropertyChangedSignal("Value"):Connect(function()
    print("changed")
    if dmg.Value >= 2 then
        block:Destroy()
        print("destroy")
    elseif dmg.Value < 2 then
        print("safe")
    end
end)
0
Nothing's happening even with the local vars. Flannelling 4 — 5y
0
Does it still not work? crywink 419 — 5y
0
Yup. Not working at all. Flannelling 4 — 5y
0
Called, not fired User#24403 69 — 5y
View all comments (2 more)
0
How do I make it fire? Flannelling 4 — 5y
0
try dmg.Changed DeceptiveCaster 3761 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

I resolved this by moving everything into one script. Rather than using an IntValue, I made a local counter value that destroyed the block after it was reached within the tool's script. This has some bugs to be worked out such as random blocks I don't want to be destroyed being included, but I'll figure that out shortly. Thanks to everyone who helped!

--- VARS ---
local tool = script.Parent.Parent -- refers to tool container
local player = game.Players.LocalPlayer -- finds local player who's running game
local mouse = player:GetMouse() -- finds the players cursor
distance = 8 -- distance you need to be from block
local num = 1 -- baseline amt of damage dealt
debounce = false
local dmg = 2 -- total dmg before destroy
local counter = 0

--- DAMAGE ---

tool.Activated:Connect(function()
    if mouse.Target ~= nil and debounce == false and mouse.Target.ClassName == "Part" 
    and (mouse.Target.Position - script.Parent.Position).Magnitude < distance then
    debounce = true
    wait(.75)
    debounce = false
    counter = counter + 1
    print(counter)
    end
end)

-- DESTROY -- 

tool.Activated:Connect(function()
    if counter >= dmg - 1 then
        mouse.Target:Remove()
        counter = 0
    end
end)

Answer this question