My problem is I have a checkpoint system on a server script that changes color when its touched. however, because it is not running on each individual client everyone can see the checkpoint’s color change when just one person touches the checkpoint but when I place my script in a local script it breaks and in the toolbox I think almost all free checkpoint for obby models are on a server script so I assume there has to be a reason for that. But how do I make it run on each individual client so that not everyone can see the checkpoint color change when someone else steps on it.
-- Define the starting and ending color and material
local startColor = Color3.new(1, 0.666667, 1)
local endColor = Color3.new(0, 1, 0)
local startMaterial = Enum.Material.SmoothPlastic
local endMaterial = Enum.Material.Neon.Value
local CollectionService = game:GetService("CollectionService")
local CheckPoints = CollectionService:GetTagged("CheckPoints")
-- Define the duration of the color change in seconds
local duration = 1
-- Keep track of the last checkpoint each player touched
local lastCheckpointValues = {}
-- Define the function to tween the part's color and material
local function tweenColor(part)
-- Create the color and material tweens
local colorTween = game:GetService("TweenService"):Create(part, TweenInfo.new(duration), {Color = endColor})
local materialTween = game:GetService("TweenService"):Create(part, TweenInfo.new(duration), {Material = endMaterial})
-- Play the tweens in parallel
colorTween:Play()
materialTween:Play()
end
-- Set up the Touched event for each checkpoint
for i, checkpoint in ipairs(CheckPoints) do
checkpoint.Touched:Connect(function(hit)
local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
if player and player.Character and player.Character:FindFirstChild("Humanoid") then
-- Disable the last checkpoint the player touched
local lastCheckpoint = lastCheckpointValues[player.UserId]
if lastCheckpoint then
lastCheckpoint.Color = startColor
lastCheckpoint.Material = startMaterial
end
-- Set the new checkpoint as the last checkpoint the player touched
lastCheckpointValues[player.UserId] = checkpoint
-- Tween the checkpoint's color and material
tweenColor(checkpoint)
end
end)
end
-- Set each player's respawn location based on the last checkpoint they touched
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
repeat task.wait() until character.Parent ~= nil
local lastCheckpoint = lastCheckpointValues[player.UserId]
if lastCheckpoint and character:FindFirstChild("Humanoid") then
local spawnPart = lastCheckpoint
character.HumanoidRootPart.CFrame = spawnPart.CFrame + Vector3.new(0, 0, 0)
end
end)
end)