I am trying to make a system like MasterDaniel’s Masters Difficulty Chart Obby where whenever you step on a checkpoint, it turns green only for the client (example). I was able to get it to work using remote events but the problem was, the remote event only worked for one checkpoint and I was going to have to have remote events for each checkpoint. Is there any way I can make my checkpoints turn green only for the client without having to make a remote event for all 100 of my stages? My scripts are shown below (Both my local script and my checkpoint server script)
Local Script:
game.ReplicatedStorage.CheckpointColorEvent.OnClientEvent:Connect(function()
local Checkpoints = game.Workspace.Checkpoints:GetChildren()
for i, v in pairs(Checkpoints) do
v.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
v.BrickColor = BrickColor.new("Lime green")
end
end)
end
end
Checkpoint Server Script:
checkpoint.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild('Humanoid') then
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
plr.leaderstats.Stage.Value = 1
game.ReplicatedStorage.CheckpointColorEvent:FireClient(plr)
end
end)
You can try passing the level part as a parameter and use it to change the color to lime green in the local script, pass the name of the part which was touched and use a for loop and if the name of the part which was sent as a param is present you can change its color
Heres the edit of your script.
ServerScript:
checkpoint.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild('Humanoid') then
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
plr.leaderstats.Stage.Value = 1
game.ReplicatedStorage.CheckpointColorEvent:FireClient(plr,checkpoint.Name)
end
end)
edit: I dont really know how you defined checkpoint so Ima just assume its a for loop too or just a part defined as checkpoint.
Local Script:
game.ReplicatedStorage.CheckpointColorEvent.OnClientEvent:Connect(function(checkpointName)
local Checkpoints = game.Workspace.Checkpoints:GetChildren()
for i, v in pairs(Checkpoints) do
if v.Name == checkpointName then
v.BrickColor = BrickColor.new("Lime green")
end
end
end)
checkpoint.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild('Humanoid') then
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if plr then --Also add a check to see if the player exists
plr.leaderstats.Stage.Value = 1
game.ReplicatedStorage.CheckpointColorEvent:FireClient(plr, checkpoint)
end
end
end)
To make it work for every checkpoint you can use a loop
Server script:
local Checkpoints = workspace.Checkpoints:GetChildren()
for i, checkpoint in pairs(Checkpoints) do
checkpoint.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild('Humanoid') then
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if plr then --Also add a check to see if the player exists
plr.leaderstats.Stage.Value = 1
game.ReplicatedStorage.CheckpointColorEvent:FireClient(plr, checkpoint)
end
end
end)
end