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
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)
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.
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.