If equal to script not working

I’m trying to create a slender clone for fun and I got all the basics down. But right now i’m trying to make a script where the game ends when all 8 pages are collected. However, it’s not working and I do not know what’s wrong with it. Here’s the script.

while true do
wait()
if workspace.PageCounter.Value == 8 then
script.Disabled = true
workspace.EndGame.Disabled = false
end
wait()
end

I’m really confused why you would use the Disabled toggle method. Can you consider using functions instead? :thinking:


I don’t see a script that updates workspace.PageCounter.

Use ``` to format code, it makes it easier to read.

You are disabling the script before it disables EndGame.

script.Disabled = true --disables script
workspace.EndGame.Disabled = false --never runs

Something you can do instaid of a loop is using the .Changed event of PageCounter.

workspace.PageCounter.Changed:Connect(function()
--this will run each time PageCounter changes.
if workspace.PageCounter.Value == 8 then
workspace.EndGame.Disabled = false
script.Disabled = true
end
end)

(sorry for no tabs, it doesn’t work for me )

1 Like

The line

workspace.EndGame.Disabled = false

won’t run because you disables the script before you get to that line.

1 Like

I merged the workspace.PageCounter.Changed:Connect(function() line for easier use and it works. It doesn’t work when I put the if workspace.PageCounter.Value == 8 then line though so the problem seems to be coming from there.

Oh, the scripts that update the PageCounter’s value are inside the pages themselves. But the other post by jaschutte gave me insight on the .Changed function so right now i’m implementing it into the endgame script itself.

Did you swap script.Disabled = true and workspace.EndGame.Disabled = false around?
Like what @CaptinLetus said,

Yeah, but it’s not really needed anymore since i’ve implemented a .Change function into the actual endgame script. So right now i’m just looking for how to get the if workspace.PageCounter.Value == 8 then working inside the function. Since it’s not working for some reason.

Have you verified that PageCounter is properly incrementing?

Also, make sure that PageCounter is an IntValue. NumberValues can store floating point values where 7+1 can actually equal 8.00000123, which does not equal 8.

2 Likes

Yeah, PageCounter is properly incrementing. I’ll change PageCounter to a IntValue and see if it works.

Thank you! Your solution and jaschutte’s solution combined helped a ton!

1 Like