Simple, step on a brick and a GUI clones into your PlayerGui from Replicated Storage. For some reason it always says that on line 7 the attempt to index a local "human" is nil? How? I'm missing something pretty simple here and I cant figure out what it is. I've tried multiple workarounds all of them have issues finding the PlayerGui.
local t = false script.Parent.Touched:connect(function(hit) if t == false then t = true wait(1) local human = game.Players:FindFirstChild(hit.Parent.Name) local jo = game.ReplicatedStorage.JOBS.Cashier:Clone(human.PlayerGui) script.Parent.Transparency = 1 script.Parent.CanCollide = false t = false wait(600) script.Parent.Transparency = 0 script.Parent.CanCollide = true end end)
Any help is greatly appreciated this is getting to me.
The Touched event fires whenever something touches the specified object. Perhaps it wasn't a player that touched the object when the event fired? That would make line 7 nil.
Check if 'human' exists before proceeding with the code.
Also, you need to set the Parent property of the cloned object. Supplying an argument to the Clone
function when you're invoking it as a method does nothing.
local db = false local cashier = game.ReplicatedStorage.JOBS.Cashier script.Parent.Touched:connect(function(hit) if not db then db = true wait(1) local human = game.Players:FindFirstChild(hit.Parent.Name) if human then local jo = cashier:Clone() jo.Parent = human.PlayerGui script.Parent.Transparency = 1 script.Parent.CanCollide = false wait(600) script.Parent.Transparency = 0 script.Parent.CanCollide = true end db = false end end)
I doubt it errors on line 7, it probably errors on line 8 when you try to index a "human" that you failed to find. Try using more checks to make sure the toucher is a player. By the way , "Clone" does not take a parameter; you must parent it yourself.
local t = false script.Parent.Touched:connect(function(hit) if t == false then t = true wait(1) local char = hit.Parent --very useful! local human = game.Players:GetPlayerFromCharacter(char) if human then local jo = game.ReplicatedStorage.JOBS.Cashier:Clone() jo.Parent = human.PlayerGui script.Parent.Transparency = 1 script.Parent.CanCollide = false t = false wait(600) script.Parent.Transparency = 0 script.Parent.CanCollide = true end end end)