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

how to transfer a code from when clicked to when called on?

first of sorry if the title is weird didn't really know what to call it so I've got this code here that when the player clicks on the part the player is teleported to somewhere on the map facing a certain direction my problem is i want to do that but not when the player clicks the part but when called on like for example if the player press e. I've been told to just take it out of the loop but that's the problem the loop connects and define Player and i cant take it out without redefining Player which i don't know how to do and is what i'm asking help for. i will happily ask any questions.

here is the code:

game.Workspace.Hello.ClickDetector.MouseClick:Connect(function(Player)
	
    local CharacterModel = Player.Character 
	 
    CharacterModel:SetPrimaryPartCFrame(CFrame.new(1, 0, 1) * CFrame.Angles(math.rad(0), math.rad(80), math.rad(0)))

   
    
end) 

1 answer

✓ Accepted answer

Try this for the variable.

local CharacterModel = game.Players.LocalPlayer

and if that doesn't work,

local plr = game.Players.LocalPlayer
local CharacterModel = plr.Character

Both should work haha.

2 comments

0

ok

0

thank you for this it did not work but it was the cframe bringing up problems now so in other words you helped me thanks!

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