Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

I am having a problem with my checkpoint script for my obby that i am working on. How to fix this?

Asked by 4 years ago
Edited 4 years ago

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:

01local StageValue = 0
02local debounce1 = false
03local Touched1 = false
04 
05workspace.Stages.Stage1.Touched:Connect(function(hit)
06    if hit.Parent:FindFirstChildOfClass("Humanoid") and not debounce1 and not Touched1 then
07Touched1 = true
08        StageValue = StageValue + 1
09 
10        if StageValue == 1 then
11            print("StageValue is now 1")
12            workspace.Stages.Stage1.CanCollide = false
13            workspace.Stages.Stage1.Transparency = 1
14            workspace.Stages.Stage1.Sparkles.Enabled = false
15            local debounce1 = true
16        end
17    end
18end)

This is all in a script not a local script and the script is located in the workspace.

0
Local programs operate on the Client machine, whilst Server (regular) Scripts run on the ROBLOX Server. The Server, as all Servers, manage all Clients, meaning any action performed through a ServerScript will occur for everyone. Use a LocalScript to solve this issue. Ziffixture 6913 — 4y
0
I did... BUT the script did not work. JOZOUMRO11 34 — 4y

2 answers

Log in to vote
2
Answered by 4 years ago
Edited 4 years ago

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:

01local 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
07end
08 
09for _, 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)
13end
14 
15CS:GetInstanceAddedSignal("Checkpoint"):Connect(function(Part) --If using a folder, do `folder.ChildAdded`
16    Part.Touched:Connect(function(Hit)
17        checkpoint(Hit, Part)
18    end)
19end)
0
lets say i want to move an part called Stage1 located in a folder called Stages. Where would i put that part of the script? JOZOUMRO11 34 — 4y
0
Well, this is general, not part specific. You could put, inside the function, if stage.Name == "1" then yada yada yada NickIsANuke 217 — 4y
0
Thank you. JOZOUMRO11 34 — 4y
Ad
Log in to vote
1
Answered by 4 years ago

Hi Jozou,

If you want this all to be managed for each client, then you need to use a local script and use FilteringEnabled. Use LocalPlayer instead. I would keep the Touched function in the server, and when the part is touched it sends a signal to the local script to fire and change that part's transparency. You would use RemoteEvents to send signals back and forth between the client and server, and you'd need to place this RemoteEvent in ReplicatedStorage, since that place is accessible by both client and server. It would look something like this:

Local Script:

1local players = game:GetService("Players")
2local player = players.LocalPlayer
3local re = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")
4 
5re.OnClientEvent:Connect(function(part)
6    part.Transparency = 1
7end)

Server Script

01local part = script.Parent
02local re = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")
03local players = game:GetService("Players")
04local deb = false
05 
06part.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
12end)

Go here to find out more about FilteringEnabled.

Go here to find out more about LocalScripts.

Go here to find out more about RemoteEvents.

Thanks,

Best regards,

Idealist Developer

0
When i use this i get: Infinite yield possible on 'ReplicatedStorage:WaitForChild("RemoteEvent")' JOZOUMRO11 34 — 4y
0
And i get this too: ScriptNavigationHandler : No script currently available. JOZOUMRO11 34 — 4y
0
That is because RemoteEvent is not in the correct location. I am not sure about the ScriptNavigationHandler. I don't think that has anything to do with your own script. IdealistDeveloper 234 — 4y

Answer this question