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

Why won't the Instance parent to the character?

Asked by 2 years ago
Edited 2 years ago

I'm making a running script for all platforms. It took me like 3 days to make because of bugs and stuff. For the running script for controller, I made it so it puts a boolean value inside of the player's character that sees if the player is running or not. This is so when the player presses a button on the controller, it makes you run, but then when you press the same button after, it stops running. This is the part of the script I used to add the boolean value.

local char = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait() 
game.Players.LocalPlayer.CharacterAdded:Connect(function() 
boolean = Instance.new("BoolValue") 
    boolean.Parent = char 
    boolean.Name = "run"
    boolean.Value = false 
end)

In the code I said, "boolean.Parent = char", yet the value doesn't appear anywhere. It's probably still parented to nil, and I don't know why.

2 answers

Log in to vote
1
Answered by 2 years ago

Alright so I instantly saw what your problem was here, you are looking for the character then looking for the character to be added again. When using CharacterAdded:Connect(function() it sends over the new player character. So instead of what you had, your code should be this:

game:GetService("Players").LocalPlayer.CharacterAdded:Connect(function(Char)
    local boolean = Instance.new("BoolValue")
    boolean.Parent = char
    boolean.Name = "run"
    boolean.Value = false
end)

Another way you could do it is a local script in the StarterCharacterScripts under StarterPlayer with just the boolean creation.

Hopefully this helps.

Ad
Log in to vote
0
Answered by
enes223 327 Moderation Voter
2 years ago

hey you! have you ever heard of enes? if you are in trouble, better call enes!

Answer this question