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:

local StageValue = 0
local debounce1 = false
local Touched1 = false

workspace.Stages.Stage1.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChildOfClass("Humanoid") and not debounce1 and not Touched1 then
Touched1 = true
        StageValue = StageValue + 1

        if StageValue == 1 then
            print("StageValue is now 1")
            workspace.Stages.Stage1.CanCollide = false
            workspace.Stages.Stage1.Transparency = 1
            workspace.Stages.Stage1.Sparkles.Enabled = false
            local debounce1 = true
        end
    end
end)

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:

local function checkpoint(Hit, Part)
    if Players:GetPlayerFromCharacter(Hit.Parent) then
        local stageNumber = Part.Parent.Name
        local player = Players:GetPlayerFromCharacter(Hit.Parent)
        player.leaderstats:WaitForChild("Stage").Value = stageNumber
    end
end

for _, Part in pairs(CS:GetTagged("Checkpoint")) do --If using a folder, do `folder:GetChildren`
    Part.Touched:Connect(function(Hit)
        checkpoint(Hit, Part)
    end)
end

CS:GetInstanceAddedSignal("Checkpoint"):Connect(function(Part) --If using a folder, do `folder.ChildAdded`
    Part.Touched:Connect(function(Hit)
        checkpoint(Hit, Part)
    end)
end)
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:

local players = game:GetService("Players")
local player = players.LocalPlayer
local re = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")

re.OnClientEvent:Connect(function(part)
    part.Transparency = 1
end)

Server Script

local part = script.Parent
local re = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")
local players = game:GetService("Players")
local deb = false

part.Touched:Connect(function(hit)
    local hum = hit.Parent:FindFirstChildOfClass("Humanoid")
    local plr = players:GetPlayerFromCharacter(hit.Parent)
    if not deb and hum and plr then
        re:FireClient(plr, part)
    end
end)

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