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

Why does this script only work in Studio mode?

Asked by
Seraine 103
9 years ago

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
You can't use :LoadCharacter() from a localscript SurVur 86 — 9y

1 answer

Log in to vote
2
Answered by
dyler3 1510 Moderation Voter
9 years ago

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

0
Why would you change this into a serverside script? NotsoPenguin 705 — 9y
0
Thanks it works :) Seraine 103 — 9y
0
No prob :P Glad I could help. NotsoPenguin, you can't use :LoadCharacter in a LocalScript. That's why. dyler3 1510 — 9y
Ad

Answer this question