ERROR: 16:43:23.107 - Players.Player.PlayerGui.Hole.Frame.GreenButton.Green.Scrip:6: attempt to index local 'hit' (a nil value)
local Btn = script.Parent local Gui = Btn.Parent.Parent.Parent TeleportPart = workspace["4"] function Click(hit) print(hit.Parent) local humanfound = hit.Parent:FindFirstChild("Humanoid") local playerfound = game.Players:GetPlayerFromCharacter(hit.Parent) if hit.Parent and humanfound and humanfound.Health > 0 and playerfound then hit.Parent:MoveTo(TeleportPart.Position) end end Btn.MouseButton1Click:connect(Click)
Your problem is that there are no arguments in this specific event/function. Therefore, we simply need to get the player a different way. Make sure that this is in a LocalScript, and follow what I do.
First, we need to simply get the player. To do this, we'll use LocalPlayer
. This gets the player from a LocalScript, as long as it's a descendent of the Player, the Backpack, or the PlayerGui. Here's what it will look like:
Player=game.Players.LocalPlayer
So now we have that set. Onto the next part.
For this part, we simply need to setup the function differently. Here's how it should look:
function Click() if Character:FindFirstChild("Humanoid") then local Humanoid=Character.Humanoid if Humanoid.Health > 0 then Character.HumanoidRootPart.CFrame=CFrame.new(Vector3.new(TeleportPart.Position)) end end end Btn.MouseButton1Click:connect(Click)
So basically, that's it.
Now, we'll put the entire script together for you:
local Btn = script.Parent local Gui = Btn.Parent.Parent.Parent TeleportPart = workspace["4"] Player=game.Players.LocalPlayer repeat wait() until Player.Character Character=Player.Character function Click() if Character:FindFirstChild("Humanoid") then local Humanoid=Character.Humanoid if Humanoid.Health > 0 then Character.HumanoidRootPart.CFrame=CFrame.new(Vector3.new(TeleportPart.Position)) end end end Btn.MouseButton1Click:connect(Click)
Anyways, hope I helped, if you have any further questions/problems, please leave a comment below :P