What do you want to achieve? I want to reset checkpoints
What is the issue? I dont know how to make it
What solutions have you tried so far? I tried whatever i can but im still new at scripting so i couldnt make it
There is my Checkpoint code:
local Checkpoints = game.Workspace:WaitForChild("Checkpoints")
game.Players.PlayerAdded:Connect(function(plr)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = plr
local v = Instance.new("IntValue")
v.Name = "Stage"
v.Value = 1
v.Parent = leaderstats
plr.CharacterAdded:Connect(function(char)
local hum = char:WaitForChild("Humanoid")
wait()
char:MoveTo(Checkpoints[v.Value].Position)
hum.Touched:Connect(function(hit)
if hit.Parent == Checkpoints then
if tonumber(hit.Name) == v.Value+1 then
v.Value = v.Value +1
end
end
end)
end)
end)
What should i do ? Should i change the checkpoint script or should i use DataStoreService ?
-- Client Side
-- Make a Remote Event, so when the touch event is fired it also fires a RemoteEvent
-- Services
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ResetCheckpointEvent = ReplicatedStorage.RemoteEvent
game.Workspace.Cellatbaba.Hitbox.Touched:Connect(function(hit)
if Players:GetPlayerFromCharacter(hit.Parent) then
-- Set Characters health to 0
ResetCheckpointEvent:FireServer()
end
end)
Now on the server you can do
-- Server Script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ResetCheckpointEvent = ReplicatedStorage.RemoteEvent
ResetCheckpointEvent .OnServerEvent:Connect(function(player)
player.leaderstats.Stages.Value = 0
end
You’re attempting to find the leaderstats already with game.Players:WaitForChild("leaderstats", 1) without implementing a check inside your Touched event
What I’d do is create a Player variable inside your Touched event, check if the Player & leaderstats are valid, then just reset back their stats to 0:
local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
if Player then
hit.Parent.Humanoid.Health = 0
workspace.CellatBaba:SetPrimaryPartCFrame(CFrame.new(0, 0, 0))
local leaderstats = Player:WaitForChild("leaderstats", 1)
if leaderstats then
leaderstats.Stage.Value = 0
end
end
Oh right, I always make changes to the players data on the server, but in this case I don’t think you really need to use a RemoteEvent. Either way should work fine.
The function literally is what it says: Gets the Player Object from the Character Model that hit the part
If I were to put this:
local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
hit is referring to the actual part name that it hit, but we don’t want that (Right Arm, Left Leg, etc)
Instead, we use hit.Parent to get the HitPart’s parent (Or in this instance, the Character’s Model)
That way, we’ll be able to access both the Player & Character just from using a Touched event but we wanna change the leaderstats so we use Player.leaderstats.Stage.Value = 0 instead
Thank you for answer, i think we solved the problem but we have another problem even if i change the stages it doesnt change the spawnpoint. Should i create another topic for that problem ?