when the script runs, i get an error Players.ieatandisbaconhair.PlayerGui.LocalScript:4: attempt to index local 'player' (a nil value). How do i fix it? thanks!

script:

local debounce = false
local cam = game.Workspace.CurrentCamera
game.ReplicatedStorage.EnterPaintShop.OnClientEvent:Connect(function(player)
	local player = player
			for i,v in pairs(player.Character:GetChildren())do
	if v:IsA("Model") and v.Name == player.Name.."'s Car" then
	v:Destroy()
	end
	for _,k in pairs(cam:GetChildren())do
	k:Destroy()
	end
	if not debounce then
	debounce = true
	local c = player:WaitForChild("SelectedCar").Value:Clone()
	c.Parent = game.Workspace.CurrentCamera
	c:SetPrimaryPartCFrame(game.Workspace.painttp.CFrame)
	player.Character.Torso.CFrame = player.Character.Torso.CFrame + Vector3.new(3,0,3)
	player.Character.Humanoid.WalkSpeed = 0
	player.PlayerGui.PaintGUI.Enabled = true
	cam.CameraSubject = game.Workspace.painttp
	debounce = false
		end
		end
end)

8 comments

0

There's no built in player argument with OnClientEvent, the variable player is nil unless you specifically sent an argument via the server

0

oh, thanks!

0

Vulk, I thought it was opposite...

0

No problem

0

Shouldn't be the opposite, OnServerEvent has the argument built in because it needs to know which client fired the event, OnClientEvent on the other hand can only be sent from the server

0

When i step in the pad, nothing is happening. i used for i,v game

0

well make sure you got the :FireServer method

0

this is supposed to show a gui for a player when a player steps in a pad