How do you make a checkpoint rotates once per player and locally. Im not really good at scripting.
To do it locally, you’d obviously need a LocalScript. A LocalScript only runs when parented to certain things, which you can read here. What I would do is first, put all the checkpoints in a folder and name it CheckpointsFolder
Then put a LocalScript in StarterPlayer > StarterCharacterScripts and write the following;
local TweenService = game:GetService("TweenService");
local checkpoints = workspace:WaitForChild("CheckpointsFolder"); --You can change CheckpointsFolder this to whatever you named the folder.
local character = script.Parent;
for _, checkpoint in next, checkpoints:GetChildren() do --Loops through all the checkpoints in the folder
--I'm assuming each checkpoint is a SpawnLocation or a part, if not, you can tell me and I'll rewrite this.
local rotateTween = TweenService:Create(
checkpoint,
TweenInfo.new(1), --Change 1 to how long (in seconds) you want the rotation to be
{Orientation = checkpoint.Orientation + Vector3.new(0, 360, 0)}
)
--This makes a tween that will tween the orientation of the checkpoint by 360 degrees.
local connection;
connection = checkpoint.Touched:Connect(function(hit)
if hit:IsDescendantOf(character) then --Checks if what touched the checkpoint was part of your character
connection:Disconnect(); --This will stop this function from running after it's been touched by your character
rotateTween:Play(); --Plays the tween!
end
end)
end
Omg tysm! It worked! Ive been looking for days i finally know it tyy!
Oh btw do you know how to make it become green after it spins
Yes, do this;
local TweenService = game:GetService("TweenService");
local checkpoints = workspace:WaitForChild("CheckpointsFolder"); --You can change CheckpointsFolder this to whatever you named the folder.
local character = script.Parent;
for _, checkpoint in next, checkpoints:GetChildren() do --Loops through all the checkpoints in the folder
--I'm assuming each checkpoint is a SpawnLocation or a part, if not, you can tell me and I'll rewrite this.
local rotateTween = TweenService:Create(
checkpoint,
TweenInfo.new(1), --Change 1 to how long (in seconds) you want the rotation to be
{Orientation = checkpoint.Orientation + Vector3.new(0, 360, 0)}
)
--This makes a tween that will tween the orientation of the checkpoint by 360 degrees.
local connection;
connection = checkpoint.Touched:Connect(function(hit)
if hit:IsDescendantOf(character) then --Checks if what touched the checkpoint was part of your character
connection:Disconnect(); --This will stop this function from running after it's been touched by your character
rotateTween:Play(); --Plays the tween!
checkpoint.Color = Color3.fromRGB(0, 255, 0); --Changes the color
end
end)
end
ty but it didnt work now? the one without color work. this didnt work?
It should work? Did you replace the code I originally sent? It works for me
oops i forgot to change the folder name thing. it works lol. tysm
sadly if you reset or rejoin you touch it it will still spin
Good catch. Make a ScreenGui in StarterGui and make sure the ResetOnSpawn
property is false. Put this script in the ScreenGui and change the code to this;
local Players = game:GetService("Players");
local TweenService = game:GetService("TweenService");
local checkpoints = workspace:WaitForChild("CheckpointsFolder"); --You can change CheckpointsFolder this to whatever you named the folder.
local character = Players.LocalPlayer.Character or Players.LocalPlayer.CharacterAdded:Wait();
for _, checkpoint in next, checkpoints:GetChildren() do --Loops through all the checkpoints in the folder
--I'm assuming each checkpoint is a SpawnLocation or a part, if not, you can tell me and I'll rewrite this.
local rotateTween = TweenService:Create(
checkpoint,
TweenInfo.new(1), --Change 1 to how long (in seconds) you want the rotation to be
{Orientation = checkpoint.Orientation + Vector3.new(0, 360, 0)}
)
--This makes a tween that will tween the orientation of the checkpoint by 360 degrees.
local connection;
connection = checkpoint.Touched:Connect(function(hit)
character = Players.LocalPlayer.Character;
if hit:IsDescendantOf(character) then --Checks if what touched the checkpoint was part of your character
connection:Disconnect(); --This will stop this function from running after it's been touched by your character
rotateTween:Play(); --Plays the tween!
checkpoint.Color = Color3.fromRGB(0, 255, 0); --Changes the color
end
end)
end
wow tysm this works too and also thx again
it still has a little bug tho when you rejoin it still will rotate but if you reset it wont, and i also have a reset progress GUI. when they press reset the checkpoints are green when they step on it the checkpoint wont rotate too.
Just a small tip, please try and write a bit of code, that way you’re at least learning instead of other people just giving you the script. (Not tryin to sound rude but I think it’s better that way because you learn aswell)
oh ok! im gonna try a bit then TvT