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

I can't work out what's wrong?

Asked by
JJ_B 250 Moderation Voter
10 years ago

I created this lengthy (and quite messy) LOCAL script for a shuttle craft. It makes a sound to simulate takeoff, and changes a decal in front of the window every so often to show it's moving. Then it grabs another shuttle from ReplicatedStorage and teleports you to a brick at the new shuttle. I tried putting it in a regular script, to find that this only works in studio. Here is the code:

01repeat wait() until game.Players.LocalPlayer
02char = game.Players.LocalPlayer.Character
03destination = game.Workspace.planshut
04 
05function onClick()
06    script.Parent.Sound:Play()
07    wait(6)
08    script.Parent.Parent.view.Transparency = 0 -- view space
09    wait(1)
10    script.Parent.Parent.view.Decal.Transparency = 0
11    script.Parent.Parent.view.Decal.Texture = "http://www.roblox.com/asset?id=244339877" --view planet
12    wait(1)
13    script.Parent.Parent.view.Decal.Texture = "http://www.roblox.com/asset?id=244339507" -- closer view
14    wait(1)
15    script.Parent.Parent.view.Decal.Texture = "http://www.roblox.com/asset?id=244339544" -- surface view
View all 33 lines...

I can't work out what is wrong! It won't do anything, the output won't tell me anything at all either. Help?

1 answer

Log in to vote
1
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
10 years ago

When using LocalScripts, remember that LocalPlayer will always exist. No need to wait for it. You do, however, often need to wait for the character.

1local plr = game.Players.LocalPlayer
2    repeat wait() until plr.Character
3local chr = plr.Character

However, LocalScripts only run in PlayerGui or Backpack. They don't run in parts. So you must use a server Script.

But LocalPlayer only works in LocalScripts, so what do you do? Well it turns out that MouseClick events have a built in parameter equal to the Player who clicked. You can use that.

1function sayHi( plr )
2    print(plr.Name.." says hi!")
3end
4script.Parent.ClickDetector.MouseClick:connect( sayHi )

On a side note, you should really define some variables instead of using those long paths over and over.

0
I changed the script according to this, and the output tells me "Torso is not a valid member of Player" JJ_B 250 — 10y
0
Like I said, the parameter is equal to the PLAYER who clicked it. It's NOT equal to a Character. You therefore need to use the Player's Character *property*, e.g., plr.Character Perci1 4988 — 10y
Ad

Answer this question