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

I can't set a bool value to false inside the player. Any help?

Asked by
15BQT 15
2 years ago

So I'm trying to set a bool value inside the player to false whenever they die, but for some reason, the script is not working.

The Script (Client-Side)

local Player = game:GetService("Players").LocalPlayer

Player.Character.Humanoid.Died:Connect(function()
    Player:WaitForChild("Survived").Value = false -- Set the bool value to false
end)

The output also doesn't return any errors.

If you have any ideas on how I can get this working, please let me know because this function is really important for my game.

Thanks!

1 answer

Log in to vote
1
Answered by
Antelear 185
2 years ago

You cannot change values locally! You have to change them on the serverside. Now I can give a good solution and say use StarterCharacterScripts as any instance inside of it will be cloned + parented to your character. Use a ServerScript and do whatever scripting you need when you want to use this event whenever they die! (I recommend adding a variable checking when you want to run this event, i'll show you how)

ServerScript inside of StarterCharacterScripts

-- lets assume you had code up here which checked for when the round starts/ends


local Char = script.Parent -- like i said, cloned and parented to the character.
local User = game:GetService("Players"):GetPlayerFromCharacter(Char) -- this lets you access the User via their Character!

local RoundStarted = false -- change this whenever you want to check if they died + the round has started before they did so.
local Survived = User:WaitForChild("Survived") -- this is how you would get the value now!
Char:WaitForChild("Humanoid").Died:Connect(function()
    if not RoundStarted then return end -- "not RoundStarted" is equivalent to "RoundStarted == false", and it will stop the script and return nothing.
    Survived = false
end)

-- then do whatever you want via adding the people who did survive into a table and yeah yeah yeah.
--you can change the survived back to true when the round is over! and etc etc

I hope this helped you and if it did please make sure to mark this as the answer that helped you. And also check the devforum and look more into StarterCharacterScripts as it does a way better job of explaining than me! Again, hope this helped!

0
Thanks for the reply! I'll let you know if it worked. 15BQT 15 — 2y
0
An error pops up saying attempt to index nil with ''WaitForChild". Removing the "WaitForChild" also causes an error. Very strange.. 15BQT 15 — 2y
0
Hm? Could you possibly dm me on discord about this @15BQT? Antelear 185 — 2y
0
My user is Shade#7482 Antelear 185 — 2y
Ad

Answer this question