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

Why does this script only work in Studio mode?

I used a local script for this:

function onButtonClicked()
wait(0.1)
game.Players.LocalPlayer:LoadCharacter()
game.Players.LocalPlayer.PlayerGui.Bloxikin.Frame.Visible = false
game.Players.LocalPlayer.PlayerGui.Flash.LocalScript.Disabled = false
end
script.Parent.MouseButton1Down:connect(onButtonClicked)

The button works fine when I test it in studio mode, but it doesn't work when I play the game... Help please?

1 comment

1

You can't use :LoadCharacter() from a localscript

1 answer

✓ Accepted answer

Most of the time when people can't get things to work in Online mode that work in Studio, it's because they're using the wrong kind of script. Same case here.

Now, to fix the problem we would need to change this into a normal Script. The only problem with this is that you're not going to be able to access LocalPlayer. Here's a simple way to get around this:

1. Add an ObjectValue, and put this LOCALSCRIPT inside it:

script.Parent.Value = game.Players.LocalPlayer

2. Add a SCRIPT with the same parent as the ObjectValue. Now, put this code into the script:

repeat wait() until script.Parent.ObjectValue.Value --Waits to set 'Player' until it is found
Player = script.Parent.ObjectValue.Value

function onButtonClicked()
	wait(0.1)
	Player:LoadCharacter()
	Player.PlayerGui.Bloxikin.Frame.Visible = false
	Player.PlayerGui.Flash.LocalScript.Disabled = false
end

script.Parent.MouseButton1Down:connect(onButtonClicked)

Now, this should work if you do it correctly. If you have any further questions, or I made a mistake, let me know in the comments. Hope I helped :P

3 comments

0

Why would you change this into a serverside script?

0

Thanks it works :)

0

No prob :P Glad I could help. NotsoPenguin, you can't use :LoadCharacter in a LocalScript. That's why.

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