Hello, I have tried for a while and can’t get my BoolValue inside a player to destroy itself when a player clicks a text button. I need help, this is really simple so it should be an easy fix.
for i, v in pairs(game.Players:GetPlayers()) do
if v:FindFirstChild("BoolValue") then
v:Destroy()
end
end
Something along those lines ^
Clearify, what BoolValue
do you want to destroy, and why would you want to destroy them?
You could try Player.{The BoolValue inside a player}:Destroy()
.
The name of the BoolValue is Value and I want to destroy it so anyone thats afk can be counted as afk so if they click a text button it gets rid of the BoolValue so the game knows their not afk.
Do you have any script for your button?
What do you mean? Like another script in the button?
No, do you have a localscript in your button?
Yes I have another LocalScript in the TextButton, and this script is a LocalScript also.
Do you use the Value
property for something else in that BoolValue
? If not, why can’t you use the Value
property of the BoolValue instead of destroying it?
Its just the code after that would be easier if I destroyed it instead and changing the value seems harder to me.
All I want to do is have the player click a text button and this BoolValue to be destroyed when they do.
Is the bool value accessed by the server? If so, you’ll want to destroy it server-sided via a RemoteEvent.
An example of this could be (with a RemoteEvent named “DestroyBool” located in the ReplicatedStorage):
LocalScript located in a TextButton:
script.Parent.MouseButton1Down:Connect(function()
game.ReplicatedStorage.DestroyBool:FireServer()
end)
Server script:
game.ReplicatedStorage.DestroyBool.OnServerEvent:Connect(function(player)
if player:FindFirstChild("Value") then
player.Value:Destroy()
end
end)
You can find some documentation on RemoteEvents here.
If the value is only ever accessed by the client you can simply destroy the value rather than going through and doing it on the server.
Ok thanks so much! It worked I will follow you now! Thanks for the help!