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

Script works perfectly fine and exactly how I want it but doesn't work in Roblox Player?[Unsolved]

Asked by 9 years ago

I have a script, when the player joins their camera will focus on a piece until they press a button, it works exactly how I want it to work, except in Roblox Player itself! Why is that happening? here is my script

    wait(1)
    repeat
    wait(1)
    if workspace:findFirstChild("Player") then
    if script.Parent.Value == 1 and script.Parent.Parent.CamValue.Value == 1 then
    Workspace.Player.Torso.CFrame = CFrame.new(Workspace.Spawners.WhiteSpawn.Position + Vector3.new(0, 2, 0))

    elseif script.Parent.Value == 2 and script.Parent.Parent.CamValue.Value == 1 then
    Workspace.Player.Torso.CFrame = CFrame.new(Workspace.Spawners.GraySpawn.Position + Vector3.new(0, 2, 0))


    elseif script.Parent.Value == 3 and script.Parent.Parent.CamValue.Value == 1 then
    Workspace.Player.Torso.CFrame = CFrame.new(Workspace.Spawners.BlackSpawn.Position + Vector3.new(0, 2, 0))
    end
    end
    until script.Parent.Parent.CamValue.Value == 0

Please help!!! Thank you!!! P.S. Should this be in regular or local script?

0
The side script does, but this exact script doesn't it just moves the player as soon as script.Parent.Value == 1 and CamValue == 1 yogipanda123 120 — 9y
0
What do you mean by "except in Roblox Player itself" and "The side script does"? chess123mate 5873 — 9y
0
Try and rewrite your revised script here. Redbullusa 1580 — 9y

1 answer

Log in to vote
0
Answered by
Redbullusa 1580 Moderation Voter
9 years ago

First of all, fix your formatting. Indent each line appropriately, because it could get confusing to look at.

repeat
    wait(1)
    if workspace:findFirstChild("Player") then
        if script.Parent.Value == 1 and script.Parent.Parent.CamValue.Value == 1 then
            workspace.Player.Torso.CFrame = CFrame.new(workspace.Spawners.WhiteSpawn.Position + Vector3.new(0, 2, 0))
        elseif script.Parent.Value == 2 and script.Parent.Parent.CamValue.Value == 1 then
            workspace.Player.Torso.CFrame = CFrame.new(workspace.Spawners.GraySpawn.Position + Vector3.new(0, 2, 0))
        elseif script.Parent.Value == 3 and script.Parent.Parent.CamValue.Value == 1 then
        workspace.Player.Torso.CFrame = CFrame.new(workspace.Spawners.BlackSpawn.Position + Vector3.new(0, 2, 0))
        end
    end
until script.Parent.Parent.CamValue.Value == 0

Let's make some variables to assess the situation more efficiently.

CamValue = script.Parent.Parent:WaitForChild("CamValue")
SomeRandomValue = script.Parent

WhiteSpawnPos = workspace.Spawners.WhiteSpawn.Position
GraySpawnPos = workspace.Spawners.GraySpawn.Position
BlackSpawnPos = workspace.Spawners.WhiteSpawn.Position
repeat
    wait(1)
    if workspace:findFirstChild("Player") then
        if SomeRandomValue.Value == 1 and CamValue.Value == 1 then
            workspace.Player.Torso.CFrame = CFrame.new(WhiteSpawnPos + Vector3.new(0, 2, 0))
        elseif SomeRandomValue.Value == 2 and CamValue.Value == 1 then
            workspace.Player.Torso.CFrame = CFrame.new(GraySpawnPos + Vector3.new(0, 2, 0))
        elseif SomeRandomValue.Value == 3 and CamValue.Value == 1 then
            workspace.Player.Torso.CFrame = CFrame.new(BlackSpawnPos + Vector3.new(0, 2, 0))
        end
    end
until CamValue.Value == 0

The main problem I see with this script is on line 5, if there's "Player" in the workspace. Now, I'm pretty sure your user name is "yogipanda123", not "Player".

"Player" is the name of the testing player spawned in solo mode. If you want the script to work in the server, refer each player as its own with...

game.Players.LocalPlayer

(Note: LocalPlayer can only be mentioned in Local Scripts.)

repeat
    wait(.1)
until game.Players.LocalPlayer
PLR = game.Players.LocalPlayer
-- Since you want to use the Torso's (which is located in the character of the player) position, I'd recommend for you to do this:
CHAR = PLR.Character
if not CHAR then
    CHAR = PLR.CharacterAdded:wait(.1)
end
Torso = CHAR:WaitForChild("Torso")

Now, let's continue on to your "repeat" loop.

repeat
    wait(1)
    if SomeRandomValue.Value == 1 and CamValue.Value == 1 then
        Torso.CFrame = CFrame.new(WhiteSpawnPos + Vector3.new(0, 2, 0))
    elseif SomeRandomValue.Value == 2 and CamValue.Value == 1 then
        Torso.CFrame = CFrame.new(GraySpawnPos + Vector3.new(0, 2, 0))
    elseif SomeRandomValue.Value == 3 and CamValue.Value == 1 then
        Torso.CFrame = CFrame.new(BlackSpawnPos + Vector3.new(0, 2, 0))
    end
until CamValue.Value == 0

This should be a working script. Place this in StarterGui and test it out. I would love to mention other ways to make this, but to do that I would have to know the whole script(s), the purpose of SomeRandomValue, and how will the value of CamValue reach 0.

0
NOTHING SEEMS TO WORK AT ALL!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Why?!?!?!? Can't i just get this script to work! Why does it STILL ONLY WORK IN ROBLOX STUDIO!!!!!!!!!!!!!!!! I am so fed up with this script right now yogipanda123 120 — 9y
Ad

Answer this question