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

Why isn't this server script running out of studio? Filtering Problem?

Asked by
PastDays 108
6 years ago
Edited 6 years ago

It checks if a player has been moved into the storage and then moves them.

while true do
    wait(1)
    if game.ReplicatedStorage.Players.Check.Value == 3 then
        print("No Players Stored")
    elseif game.ReplicatedStorage.Players.Check.Value == 1 then
        print("Player Found")
        game.ReplicatedStorage.Players.Check.Value = 2
        local Location = game.ReplicatedStorage.Players.Player:FindFirstChildOfClass("Part")    
        Location.Parent = game.Workspace.Players
        print("Player Moved")
        game.ReplicatedStorage.Players.Check.Value = 3
    elseif game.ReplicatedStorage.Players.Check.Value == 2 then
        print("Player Move In Progress")
        wait(2)
    end
end

This script renames the part to the players name and then moves it to storage for the above script to move into the Workspace, This 2 step move has to be done as when the below script moves the part it stores it locally preventing players from seeing each other, This is also setting the value for when a part is in there, This is a Local Script.

wait(2)
local Pos = game.Workspace.Spawn.Position
local Player = script.Parent:Clone()
local NM = script.Parent.Parent.NM.Value
    Player.Name = NM
    Player.Parent = game.ReplicatedStorage.Players.Player
    Player.Position = Pos
    game.ReplicatedStorage.Players.Check.Value = 1
    print(NM, "Has been moved")
    wait(5)
script.Parent.Parent.Parent.Controls.ControlMain.Disabled = false
script.Parent.Parent.Parent.Camera.Camera.Disabled = false

1 answer

Log in to vote
2
Answered by
ee0w 458 Moderation Voter
6 years ago
Edited 6 years ago

Properly formatting/indenting code is good practice, as it allows for easier readability which in turn helps debugging. Allow me to help.

while true do
    wait(1)
    if game.ReplicatedStorage.Players.Check.Value == 3 then
        print("No Players Stored")
    else if game.ReplicatedStorage.Players.Check.Value == 1 then
        print("Player Found")
        game.ReplicatedStorage.Players.Check.Value = 2
        local Location = game.ReplicatedStorage.Players.Player:FindFirstChildOfClass("Part")    
        Location.Parent = game.Workspace.Players
        print("Player Moved")
        game.ReplicatedStorage.Players.Check.Value = 3
    else if game.ReplicatedStorage.Players.Check.Value == 2 then
        print("Player Move In Progress")
        wait(2)
        end
        end
    end
end

Now, it's much easier to spot what you did wrong:

  1. else if is not a keyword in Lua. Rather, use elseif.

  2. You added two extra ends at the bottom.

Here's the fixed script.

while true do
    wait(1)
    if game.ReplicatedStorage.Players.Check.Value == 3 then
        print("No Players Stored")
    elseif game.ReplicatedStorage.Players.Check.Value == 1 then
        print("Player Found")
        game.ReplicatedStorage.Players.Check.Value = 2
        local Location = game.ReplicatedStorage.Players.Player:FindFirstChildOfClass("Part")    
        Location.Parent = game.Workspace.Players
        print("Player Moved")
        game.ReplicatedStorage.Players.Check.Value = 3
    elseif game.ReplicatedStorage.Players.Check.Value == 2 then
        print("Player Move In Progress")
        wait(2)
    end
end

Hope I helped!

0
Sorry about that i will keep that in mind next time i post, The script still doesn't work, it doesn't print anything and when checking its activity in game it says it isn't active. PastDays 108 — 6y
0
How ether in studio it works perfectly so any help here would be much appreciated. PastDays 108 — 6y
0
This is all I can do for how much info you've given. ee0w 458 — 6y
0
Please wait there ill update it with more scripts that may be relevant, I really need this working thank you for your help! PastDays 108 — 6y
0
If this isn't enough info i could always allow you to enter my game and take a look. PastDays 108 — 6y
Ad

Answer this question