Model that exists script says doesn't

Hi,

so this is in a script:

player = script.Parent.Parent.Parent.Parent.Parent
print(player)
char = workspace:WaitForChild(player)


script.Parent.MouseButton1Click:Connect(function()
	char.BodyColor.Value = script.Parent.TextButton_Roundify_12px.ImageColor3
end)

so it’s all working find and correctly, but for some reason it says that char doesn’t exist??

in the explorer i can see that my character appears there but for some reason it completely ignores it??

can i have some help?

1 Like

Hiwi!
And what the print says?

print(script.Parent.Parent.Parent.Parent.Parent)
print(script.Parent.Parent.Parent.Parent.Parent.ClassName)

Not sure how to clearly explain what’s wrong, but the third line is incorrect.

———

You could just use player.Character instead of waiting for the player in the workspace.

Additionally, if you wanted to use WaitForChild, you would have to use player.Name. This is because the “player” variable is a path, not a string, and WaitForChild requires a string as a parameter.

———

Sorry for the bad explanation, hope this helps.

2 Likes

If you are on a local script. Looks like you are, just use

local clientPlayer = game:GetService("Players").LocalPlayer to get the player. So you dont need to build that giant ladder of parents

local clientPlayer = game.Players.LocalPlayer (??)

I dont know what is better or why :v

1 Like

1 answer is they’re both technically the same

So assuming this is a local script you could probably use this (Not tested)

local player = game.Players.LocalPlayer -- This gets the player
local char = player.Character or player.CharacterAdded:Wait() -- This gets the character if it exists otherwise it waits until it exists and then sets the char as the character.

script.Parent.MouseButton1Click:Connect(function() -- Make sure script.Parent is a TextButton or ImageButton
    char.BodyColor.Value = script.Parent.TextButton_Roundify_12px.ImageColor3 -- Sets the body color of the character
end)

You Could Change
char = workspace:WaitForChild(player)
To
char = workspace:WaitForChild(player.Name)

well it’s not a local script so…

If you are not in a local script. You are using a function that a GUI uses, and GUI’s are accesable from the Client

image

You are trying to use a GUI click event from a server script then? That should not work…

https://developer.roblox.com/en-us/api-reference/event/GuiButton/MouseButton1Click

Try making a wait for child function

You should make it a local script. A regular script should not be used on the client. If you depend on this for server side stuff you should use remote events

1 Like