Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

This function isn't working properly, why?

So, this I tested this in a local script, and a server script (default script), and none of them are working. This script was originally designed to work to the extent where when a player clicks the gui button, it teleports them, makes the gui non-visible, and locks the players screen in first person.

However, it isn't working. Help?

local Button = script.Parent
Frame = script.Parent.Parent.gggg


function onClick() 
game.Players.LocalPlayer.Character.Torso.CFrame = CFrame.new(-0,1,43)
wait()
	game.Players.LocalPlayer.Character.Torso.Anchored=true
	
	wait()

Frame.Visible = false

end 

Button.MouseButton1Click:connect(onClick)

5 comments

1

You're using LocalPlayer, so you must use a LocalScript.

0

I'm using a LocalScript.

0

Tested, works as it should.

0

Is your script in a gui?

0

2 answers

✓ Accepted answer

Here is your final script:

local Button = script.Parent
Frame = script.Parent.Parent


function onClick() 
game.Players.LocalPlayer.Character.Torso.CFrame = CFrame.new(-0,1,43)
wait()
game.Players.LocalPlayer.Character.Torso.Anchored=true
wait()
game.Players.LocalPlayer.CameraMode = "LockFirstPerson"
Frame.Visible = false
end 

Button.MouseButton1Click:connect(onClick)

1 comment

0

Thanks, helped a lot.

Awesome, thanks guys I got it to function properly! Now I'm just experiencing one more tiny problem. First person isn't locking when the button is clicked.

local Button = script.Parent
Frame = script.Parent.Parent


function onClick() 
game.Players.LocalPlayer.Character.Torso.CFrame = CFrame.new(-0,1,43)
wait()
	game.Players.LocalPlayer.Character.Torso.Anchored=true
	
	wait()

Frame.Visible = false
script.Parent.Parent.CameraMode="LockFirstPerson"
end 

Button.MouseButton1Click:connect(onClick)

I have script.Parent.Parent.CameraMode="LockFirstPerson" which should be correct, this script is local and it's in StarterGui.

7 comments

0

Here was my previous problem in which it wasn't working: 'Frame = script.Parent.Parent.gggg' .gggg wasn't necessary

0

I've done the way I did previously before and it worked fine, I just haven't put it into a scrypt like this.

0

Figured it out: game.Players.LocalPlayer.CameraMode = "LockFirstPerson"

0

Isn't it sopoused to be game.Players.LocalPlayer.CameraMode.LockFirstPerson = true?

0

Both should work, however I haven't tested it.

0

You could try and use an enumeration: game.Players.LocalPlayer.CameraMode = Enum.CameraMode.LockFirstPerson

0

You could also try to adjust the property within the "StarterPlayer" object in the player.

This discussion is preserved as it was. New answers, comments, and votes are closed.