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

Why does this not detect the BoolValue being changed?

Asked by 4 years ago

I've looked all over devforum but can't seem to find an answer. Does anybody maybe know why this doesn't want to be detected?

local plr = nil
local part = script.Parent
local position1 = script.Parent.Parent.Move2.Position
local value = part.Parent.NextMove.Value

part.Touched:Connect(function(player)
    plr = player
end)
part.TouchEnded:Connect(function()
    plr = nil
end)

--Detect Value Changed and move the player

value.Changed:Connect(function()
    print("Detected")
    plr.Parent.Humanoid:MoveTo(position1)
end)

0
I'm sure it's due to plr, you weren't still touching the part so the plr is still nil, make sure to wait until the part gets touched. Could be done using 'part.Touched:Wait()' Gabe_elvin1226aclan 323 — 4y

1 answer

Log in to vote
1
Answered by
imKirda 4491 Moderation Voter Community Moderator
4 years ago

This is hard to debug for me because you have gave little information about the problem, okay it is not working, are there any errors in the output? If yes then post them everytime when making question because this is how you should debug your code.

My answer won't be accurate but i assume that

local value = part.Parent.NextMove.Value

Here, NextMove is BoolValue Instance inside of some parent and .Value is it's value, which is boolean, if it is true then you've got an error which says: Attempt to index boolean with Changed. The reason why this is happening because value variable stands for NextMove's value which is true or false and Changed cannot be called on script values (Script values are those that can't be seen in workspace, by that i mean all values inside of a script like: v = 5, v = true, v = "string", these are script values). Changed is event of all instances so what you should do is set the variable to the BoolValue instance

local value = part.Parent.NextMove

and call changed on it

value.Changed:Connect(function()
    -- la la la
end)

But this won't work if local value = part.Parent.NextMove.Value is an instance and not value

0
Thank you! It worked. crousei 2 — 4y
Ad

Answer this question