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

Teleporting script works on Studio but not on a server, can you help me fix it?

Asked by 5 years ago

Uh... i can't really know what should i say more than "Hey, this script is broken, it works perfectly on studio but not on the online game."

The script that i'm talking about is:

Door = script.Parent 
ClickDetector = script.Parent.ClickDetector
despacito = true 
Footsteps = script.Parent.Footsteps

game.Players.PlayerAdded:connect(function(Clicker)
    Persin = Clicker.PlayerGui:WaitForChild("BlackScreen")
     Frame = Persin:WaitForChild("Frame")
     Char = Clicker.Character
     Root = Char:WaitForChild("HumanoidRootPart")

ClickDetector.MouseClick:connect(function(Clicker)
    if despacito == true then
        despacito = false
    Frame.Transparency = 0.9
    wait(0.03)
    Frame.Transparency = 0.7
    wait(0.03)
    Frame.Transparency = 0.5
    Footsteps:Play()
    wait(0.03)
    Frame.Transparency = 0.3
    wait(0.03)
    Frame.Transparency = 0.1
    wait(0.03)
    Frame.Transparency = 0
    Root.CFrame = CFrame.new(Vector3.new(-137.187, 3.87, -62.108))
    wait(1)

    Frame.Transparency = 0.1
    wait(0.03)
    Frame.Transparency = 0.3
    wait(0.03)
    Footsteps:Stop()
    Frame.Transparency = 0.5
    wait(0.03)
    Frame.Transparency = 0.7
    wait(0.03)
    Frame.Transparency = 0.9
    wait(0.03)
    Frame.Transparency = 1
    despacito = true
    end
end)
end)

The problem apparently comes from being a "infinite field" on waitforchild("BlackScreen")

Even tough I made this script, meaning I have a basic grasp on scripting, but I don't understand what a "infinite field" means, maybe if you guys tell me what it is, I can fix it.

If you wonder what "blackscreen" is, it's just a GUI to make the screen fade to black.

0
Can you paste the exact error code? Pojoto 329 — 5y
0
"Infinite yeld possible on 'Players.Chris75764.Playergui:WaitForChild("Blackscreen") Chris75764 49 — 5y
0
"Infinite yeld possible on 'Players.Chris75764.Playergui:WaitForChild("Blackscreen"), Stack begin, Script.Workspace.The Door.DoorTP, Line 7, Stack end. Chris75764 49 — 5y
0
That's a warning, not an error. User#19524 175 — 5y
0
Also the server should NOT be modifying PlayerGui. User#19524 175 — 5y

2 answers

Log in to vote
1
Answered by
Pojoto 329 Moderation Voter
5 years ago

Ok, so the way testing in Roblox Studio Editor is that it acts as both the client and the server, so it's not going to always give you the same results when you test in the actual game, as a client.

First off, the "Infinite Yield" error is something you shouldn't be worrying about; if it is bothering you then you can just add a random time limit after the object you are waiting for:

Clicker.PlayerGui:WaitForChild("BlackScreen", 1000) Char:WaitForChild("HumanoidRootPart", 1000)

For your script to work in an actual game, you'll need to learn how to about FilteringEnabled and how to use RemoteEvents.

In your script you are trying to change the children under the "PlayerGui" of a player (You're trying to change the frame, the "BlackScreen").

Clicker.PlayerGui:WaitForChild("BlackScreen")

Since this is a server script, and not a client/local script, we can't actually access those properties of a player, they are private only to the player.

This means we would have to go "local", and the only way to do that is to use something called a RemoteEvent. I'm not going to explain it all to you though, you're going to have to learn it on your own.

Other Errors in Your Code

When defining variables in functions inside your script, such as your "Persin" variable, you need to add a "local" in front of it, which means it can only be accessed in that function.

Also, if you're going to add a RemoteEvent, you don't need the PlayerAdded part, it's useless because we already got the player from the ClickDetector.

Sorry if I sound a bit disheartening, but you'll need to do a bit more research, and I can't help you with that. I hope I helped you though, the fading part of the script sounds pretty cool!

0
Nono, you're not disheartening, you're actually giving me something hell of a usefull!, i already know about RemoteEvents, but might as well you give me a little tip?, basically, what part of the code needs to be set on Server script and which on local? Chris75764 49 — 5y
0
Your ServerScript should be extremely short (located in the Part that's going to be clicked on), basically all it should say is: "When part is clicked on then fire this remote event" and also the code to teleport the player, which should be short. Then in a local script somewhere in the StarterGui you should have something that says: "When the RemoteEvent is fired, --play sounds and fade--" Pojoto 329 — 5y
0
Again, thanks alot!. Chris75764 49 — 5y
Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

If your teleporting players then...

local player = game.Players.LocalPlayer
local TelePart = game.Workspace.InsertPartHere.Position

player.Character.HumanoidRootPart.CFrame = CFrame.new(TelePart)

Idk if it will work????

0
Nope, totally not. Chris75764 49 — 5y
0
It's way simplified, no Fadeout GUI, i don't even use a part as TP location, and this doesn't even have to do with the issue i had. Chris75764 49 — 5y

Answer this question