Getting an error from a script that seems fine

Title is self explanatory, error:

20:29:10.140  Players.BobygoWasTaken.PlayerGui.Main.Script.Script:7: attempt to index nil with 'FindFirstChild'

Part of the script that has the error:

local button = script.Parent
local playername = script.Parent.Parent.Parent.Parent.Name
local player = game.Workspace:WaitForChild(playername)

button.MouseButton1Click:Connect(function(player)
	local character = player
	local Data = character:FindFirstChild("Data")
	
	local Values = Data:FindFirstChild("Values")
	local canWalk = Values:FindFirstChild("canWalk")
	
	local canJump = Values:FindFirstChild("canJump")
	local humanoid = character:FindFirstChild("Humanoid")

where is this located? inside playerscripts? is it a localscript?

Try getting the player/character like so:

local player = game:GetService("Players").LocalPlayer
local character = player.Character
local button = script.Parent

button.MouseButton1Click:Connect(function(player)
	local Data = character:FindFirstChild("Data")

	local Values = Data:FindFirstChild("Values")
	local canWalk = Values:FindFirstChild("canWalk")

	local canJump = Values:FindFirstChild("canJump")
	local humanoid = character:FindFirstChild("Humanoid")
end)
2 Likes

Try changing local character = player.Character to local character = player.Character or player.CharacterAdded:Wait() If player.Character turns out to be nil, then it will go to player.CharacterAdded:Wait() where it will wait for the character to be added.

1 Like

why are you setting the character variable to player instance?? its supposed to be

local character = player.Character

that’s most likely your issue

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.