I want to make a ball script, but this error shows up and I don't know what it means

I want to make a script that turns the player the into a ball, but after trying to test out the script, I get this error message that doesn’t allow the rest of the script to play out. I added a message in the script that’s supposed to print when the entire script is done, but it doesn’t play when I test it out.

script:

local cas = game:GetService("ContextActionService")

local h = script.Parent:FindFirstChild("Humanoid")
			local plr = game.Players.LocalPlayer
			local humanoid = plr.Character:WaitForChild('Humanoid')
	local currenstate = humanoid:GetState()


local plr = game.Players.LocalPlayer

local char = plr.Character or plr.CharacterAdded:Wait() 

local debounce = false

local seat = script.Parent.RollBallScript.Seato

local ball = script.Parent.RollBallScript.RollBall

local dash = script.Parent.Dash

local stomp = script.Parent.Stomp

local function buttonPressFunction()
	if debounce == false then
		debounce = true
		
		seat:Clone()
		seat.Parent = workspace
		
		ball:Clone()
		ball.Parent = workspace
		
			local Weld = Instance.new("WeldConstraint")

Weld.Parent = seat

Weld.Part0 = seat

	Weld.Part1 = ball
		
		dash.Disabled = true
		
		stomp.Disabled = true
		
		seat.CFrame = plr.Character.HumanoidRootPart.CFrame * CFrame.new(0,0,0) * CFrame.fromEulerAnglesXYZ(0,0,0)
		
		ball.CFrame = plr.Character.HumanoidRootPart.CFrame * CFrame.new(0,0,0) * CFrame.fromEulerAnglesXYZ(0,0,0)
		
		print("Rooooooooooooolling around")
		
		
	end
	wait(10)
	debounce = false
	dash.Disabled = false
	stomp.Disabled = false
end

 
local button = cas:BindAction("DashButton", buttonPressFunction, true, Enum.KeyCode.F,Enum.KeyCode.ButtonX)


cas:SetPosition("DashButton", UDim2.new(0.58, -80, 0.15, -20))

error message: Seato is not a valid member of LocalScript “Workspace.hjfghhgglosthisuser.RollBallScript”

Can you send a screenshot of the exporer please.

Scripts that run on the client might not get everything replicated in by the time the local script is running. To be safe, you can use parent:FindFirstChild(‘Seato’) to check if a child exists, or :WaitForChild(‘Seato’) if you know that the child should exist.

Well that solved my first problem, but another problem appeared. This error message shows up:

You are trying to call “clone” on a variable that is not an object but nil. Similar issue as above, you’d want to make sure that the item exists before trying to do something with it.

local seat = model:FindFirstChild('Seat')
if seat then
-- Seat exists, so you can do stuff with it.
end

or if you know for a fact that seat exists, and you just need to wait for it to replicate:

local seat = model:WaitForChild('Seat')
-- Seat exists, so you can do stuff with it.

I got another error. Is there something wrong with the entire script?

Nope, same thing, you are trying to use the CFrame of a variable that is nil, instead of an object as expected. You’ll want to do the same method as above, but for the object that you are trying to use the CFrame of on the line that the error points to.

It is perfectly normal for scripts to use :FindFirstChild() to make sure that things exist, so don’t be afraid to do it to everything.

The ball doesn’t show up but there’s no error messages. The message at the end even got printed! It also doesn’t seem to work after it prints

current script:


local h = script.Parent:FindFirstChild("Humanoid")
			local plr = game.Players.LocalPlayer
			local humanoid = plr.Character:WaitForChild('Humanoid')
	local currenstate = humanoid:GetState()


local plr = game.Players.LocalPlayer

local char = plr.Character or plr.CharacterAdded:Wait() 

local debounce = false



local ball = script.Parent.RollBallScript:FindFirstChild("RollBall")

local dash = script.Parent.Dash

local stomp = script.Parent.Stomp

local function buttonPressFunction()
	if debounce == false then
		debounce = true
		local seat = script.Parent.RollBallScript:FindFirstChild("Seato")
if seat then
seat:Clone()
		seat.Parent = workspace
		end
		
		if seat then
seat.CFrame = plr.Character.HumanoidRootPart.CFrame * CFrame.new(0,0,0) * CFrame.fromEulerAnglesXYZ(0,0,0)
end
		
		local ball = script.Parent.RollBallScript:FindFirstChild("RollBall")
		
		if ball then
ball:Clone()
		ball.Parent = workspace
		end
		
		
		if ball then
ball.CFrame = plr.Character.HumanoidRootPart.CFrame * CFrame.new(0,0,0) * CFrame.fromEulerAnglesXYZ(0,0,0)
end

			local Weld = Instance.new("WeldConstraint")

Weld.Parent = seat

Weld.Part0 = seat

	Weld.Part1 = ball
		
		dash.Disabled = true
		
		stomp.Disabled = true
		
		
		
		print("Rooooooooooooolling around")
		
		
	end
	wait(10)
	debounce = false
	dash.Disabled = false
	stomp.Disabled = false
end

 
local button = cas:BindAction("DashButton", buttonPressFunction, true, Enum.KeyCode.F,Enum.KeyCode.ButtonX)


cas:SetPosition("DashButton", UDim2.new(0.58, -80, 0.15, -20))

Put more print statements inside of the code, after some checks to see which checks failed, and then try to figure out why the checks might be failing.

1 Like