I am having a problem with my checkpoint script. As my title said. I am trying to make my obby so when a player touches a checkpoint it dissapears. But when i test the game with 2 players when the first one touches the checkpoint for the other one it is invisible and the checkpoint stops working for the first one. What i want to do is for each player to have their own script. I am new to scripting lua c on roblox.
Here is my script:
01 | local StageValue = 0 |
02 | local debounce 1 = false |
03 | local Touched 1 = false |
04 |
05 | workspace.Stages.Stage 1. Touched:Connect( function (hit) |
06 | if hit.Parent:FindFirstChildOfClass( "Humanoid" ) and not debounce 1 and not Touched 1 then |
07 | Touched 1 = true |
08 | StageValue = StageValue + 1 |
09 |
10 | if StageValue = = 1 then |
11 | print ( "StageValue is now 1" ) |
12 | workspace.Stages.Stage 1. CanCollide = false |
13 | workspace.Stages.Stage 1. Transparency = 1 |
14 | workspace.Stages.Stage 1. Sparkles.Enabled = false |
15 | local debounce 1 = true |
16 | end |
17 | end |
18 | end ) |
This is all in a script not a local script and the script is located in the workspace.
EDIT: You can make anything happen in the two functions below, I just update a stage value.
I did this by naming each checkpoint whatever the stage is. For instance, stage 1 is 1, stage 2 is 2, etc. I then tag all of the checkpoints as "Checkpoint" using the tag editor plugin. (A folder would also work, with some minor edits to the code.) Then the server code becomes:
01 | local function checkpoint(Hit, Part) |
02 | if Players:GetPlayerFromCharacter(Hit.Parent) then |
03 | local stageNumber = Part.Parent.Name |
04 | local player = Players:GetPlayerFromCharacter(Hit.Parent) |
05 | player.leaderstats:WaitForChild( "Stage" ).Value = stageNumber |
06 | end |
07 | end |
08 |
09 | for _, Part in pairs (CS:GetTagged( "Checkpoint" )) do --If using a folder, do `folder:GetChildren` |
10 | Part.Touched:Connect( function (Hit) |
11 | checkpoint(Hit, Part) |
12 | end ) |
13 | end |
14 |
15 | CS:GetInstanceAddedSignal( "Checkpoint" ):Connect( function (Part) --If using a folder, do `folder.ChildAdded` |
16 | Part.Touched:Connect( function (Hit) |
17 | checkpoint(Hit, Part) |
18 | end ) |
19 | end ) |
Hi Jozou,
1 | local players = game:GetService( "Players" ) |
2 | local player = players.LocalPlayer |
3 | local re = game:GetService( "ReplicatedStorage" ):WaitForChild( "RemoteEvent" ) |
4 |
5 | re.OnClientEvent:Connect( function (part) |
6 | part.Transparency = 1 |
7 | end ) |
01 | local part = script.Parent |
02 | local re = game:GetService( "ReplicatedStorage" ):WaitForChild( "RemoteEvent" ) |
03 | local players = game:GetService( "Players" ) |
04 | local deb = false |
05 |
06 | part.Touched:Connect( function (hit) |
07 | local hum = hit.Parent:FindFirstChildOfClass( "Humanoid" ) |
08 | local plr = players:GetPlayerFromCharacter(hit.Parent) |
09 | if not deb and hum and plr then |
10 | re:FireClient(plr, part) |
11 | end |
12 | end ) |
Thanks,
Best regards,
Idealist Developer