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

LocalScript breaking right after a player joins and uses it?

Asked by 9 years ago

So, I have a script that shoots a bullet when a tool is selected and the mouse is clicked. The script itself works fine. But right after a player joins and uses it, just like 1 second after he/she joins, the localscript just breaks. Is there a statement that can prevent this from happening?

1
You need to share the code and the error. There isn't a `fixbugs()` line -- because the bug is there because *you told* Lua that's what you want it to do. BlueTaslem 18071 — 9y
0
Are you sure? Because the script relies on another script and together they add up to 100+ lines. Also, there's no error in the output. whyOmustOitObeOme 7 — 9y
0
P.S., I didn't want a statement that just fixes the problem. I want a statement that lets the character load before the script does its thing. whyOmustOitObeOme 7 — 9y

1 answer

Log in to vote
1
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
9 years ago

You need to be more specific when asking your questions. If your third comment to your Question had been your Question, we wouldn't have had a problem.

Anyway;

local player = game.Players.LocalPlayer
local character = player.Character
if not character then --If you manually LoadCharacter, this script will sometimes run the first time before a Character exists at all.
    player.CharacterAdded:wait()
    character = player.Character
end
while not character.Parent do wait() end
Ad

Answer this question