I’ve parented a boolValue called Ready to a Server Script in ServerScriptService. There are remote events linked within this script that respond well, but I can’t get the boolValue to stop duplicating into the player.
setReady.OnServerEvent:Connect(function()
local Ready = script.Ready
Ready:Clone().Parent = Player
Ready.Value = true
if game.StarterPlayer:FindFirstChild("Ready") then
game.StarterPlayer.Ready:Destroy()
end
end)
setUnready.OnServerEvent:Connect(function()
local Ready = script.Ready
Ready:Clone().Parent = Player
Ready.Value = false
end)
When I try and paste the “if game” statement in the other RemoteEvent, I find that the boolValue doesn’t show up within the player at all. I’m literally stuck in an all-or-nothing position.
Where have you mentioned Player? I assume this is not the full script, could you show your full script (or atleast the line where the Player variable is made)?
you can’t use StarterPlayer in your code, as it wont work at all. You have to set a player parameter when you fire to the server. Also, you are cloning the boolean every time you fire the events. Instead of that, check if there is a value. If there isn’t, clone it, or else jsut change the value of the boolean.
local ReplicatedStorage = game:GetService(“ReplicatedStorage”)
local Player = game:GetService(“StarterPlayer”)
local Remotes = ReplicatedStorage.Remotes
local Legends = ReplicatedStorage.Legends
local setReady = Remotes.SetReady
local setUnready = Remotes.SetUnready
local Ready = script.Ready
setReady.OnServerEvent:Connect(function()
print(“Hey it worked!”)
local Ready = script.Ready
Ready:Clone().Parent = Player
Ready.Value = true
if game.StarterPlayer:FindFirstChild(“Ready”) then
game.StarterPlayer.Ready:Destroy()
end
Ready.Value = true
end)
setUnready.OnServerEvent:Connect(function()
print(“It still worked!”)
local Ready = script.Ready
Ready:Clone().Parent = Player
You can’t get the player like this.
When a ServerEvent is called the Player parameter is passed to it so that’s how you can get the player:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Remotes = ReplicatedStorage.Remotes
local Legends = ReplicatedStorage.Legends
local setReady = Remotes.SetReady
local setUnready = Remotes.SetUnready
local Ready = script.Ready
setReady.OnServerEvent:Connect(function(player)
print("Hey it worked!")
if player:FindFirstChild("Ready") then
player.Ready:Destroy()
end
local Ready = script.Ready
Ready:Clone().Parent = player
Ready.Value = true
end)
setUnready.OnServerEvent:Connect(function(player)
print("It still worked!")
local Ready = script.Ready
Ready:Clone().Parent = player
Ready.Value = false
end)
But as someone said in a previous reply, I don’t understand the logic of finding the Ready.Value and destroy it only to clone it again in the next line. Just change the value of it to whatever it needs to be.
Ah, so my reasoning for Destroy:() was to prevent duplicates because with my previous script, the first event would fire and a Ready would be cloned into the StarterPlayer folder, but if it was fired again, another Ready would be cloned rather than the one already having its value be changed.
Thank you though, I think your adjustments helped.