Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do i get the player model with my code?

local Knappen = script.Parent
local function TeleporterAdams(HvemTrykkede)
	local AdamDerTrykkede = HvemTrykkede
		if AdamDerTrykkede then
		AdamDerTrykkede:GetPlayersFromCharacters()
		AdamDerTrykkede:MoveTo(-82.75, 2, -39.25)
	end
end

Knappen.ClickDetector.MouseClick:Connect(TeleporterAdams)

so before when i did a print to check if it could spot the player it did. It printed out my name but when i made it print the parent of "HvemTrykkede" it would say players. So i figured to get the model id have to use some function to find it but i dont know how to use GetPlayersFromCharacters well. When i run and click the button it doesnt teleport my character. Please help

1 comment

0

oops i realised i did a spellign mistake in the functions name

1 answer

✓ Accepted answer

Well, I'll help you with this.GetPlayersFromCharacters() is not a function of the Player, but :GetPlayerFromCharacter() is a function of the Players service, but you don't need to use that here, as MouseClick will return the player, not the character. I don't know why you're making a new variable called AdamDerTrykkede instead of just using HvemTrykkede, so I stuck with using HvemTrykkede for the whole thing. Forgive me, I wrote some of the variable names in English.

local Knappen = script.Parent
local function TeleporterAdams(HvemTrykkede)
	if HvemTrykkede.Character and HvemTrykkede.Character:FindFirstChild("Humanoid") then
		--MoveTo is a function of the Humanoid, so we're checking if the Humanoid exists
        	HvemTrykkede.Character.Humanoid:MoveTo(Vector3.new(-82.75, 2, -39.25))
	end
end

Knappen.ClickDetector.MouseClick:Connect(TeleporterAdams)

2 comments

0

when i use this script it says "Unable to cast value to Object" do you know why?

0

My bad, I forgot to make MoveTo use a Vector3 value. Try that.

This discussion is preserved as it was. New answers, comments, and votes are closed.