Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

[RESOLVED] GetPropertyChangedSignal and/or Changed not working?

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.

6 comments

0

Is there a chance that your repeat wait() is just going on a forever loop?

0

It's possible. The script doesn't work either way.

0

put a print outside of the function and test if it works

0

Anything I print outside of the function works just fine. It's just that the function itself won't go.

0

then the GetPropertyChangedSignal event isn't firing. Is there another script that changes the value? local script or server script?

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?

2 answers

✓ Accepted answer
  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)

6 comments

0

Nothing's happening even with the local vars.

0

Does it still not work?

0

Yup. Not working at all.

0

Called, not fired

0

How do I make it fire?

0

try dmg.Changed

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.