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

Character cannot be found even with great amounts of time?

Asked by 1 year ago

So I have this code below, and nothing is wrong with it as it warns me that there is no character and there is no errors, but since it never finds the character, I'm wondering why it doesn't find it as when I looked at myself in the player list, my Character was listed as a property.

local Players = game:GetService("Players")
local replstor = game:GetService("ReplicatedStorage")
local marble = replstor.Marble

Players.PlayerAdded:Connect(function(plr)
    local plrmarble = marble:Clone()
    local Character = plr:WaitForChild("Character", 10)
    if Character then
        plrmarble.Position = Character.Torso.Position
    else
        warn("Character not found")
    end
    plrmarble.Name = plr.Name .. "'s " .. "Marble"
    plrmarble.Player.Value = plr
    plrmarble.Parent = workspace
end)

1 answer

Log in to vote
0
Answered by
Puppynniko 1059 Moderation Voter
1 year ago
Edited 1 year ago

The “character” is not a child of player instead it’s a property of player use CharacterAdded:Wait() this will ensure the script resumes after the character is added

Ad

Answer this question