I can't make this code make me to turn to this object when i press on the object

Mainly im not sure if click detector is use for it since I have never use it for a long time but this code does seem to make sense but im not really sure can someone explain me what im doing wrong? (Also I think im doing smth wrong with player.character but im not really sure)

local Clickdetector = script.Parent.ClickDetector
local Players = game:GetService("Players")
local Teams = game:GetService("Teams")
game.Players.PlayerAdded:Connect(function(player)
	if player.Team == Teams.Propers then
		Clickdetector.MouseClick:Connect(function()
			wait()
			local Plant = script.Parent:Clone()
			Plant.Parent = player.Character
		end)
	end
end)

1 Like

This is basically a prophunt game and when you click on this object you turn into that object

This is what the script mainly meant to do

You don’t have to create a new MouseClick connection everytime a player joins, you can just create it once and use the ‘playerWhoClicked’ fired in the event:

local teams = game:GetService("Teams")
local clickDetector = script.Parent.ClickDetector

-- everytime the MouseClick event fires, it fires the player who clicked with it
clickDetector.MouseClick:Connect(function(player)
	-- also make sure they have a character instead of creating useless parts
	if player.Team == teams.Propers and player.Character then
		wait()
		
		local plant = script.Parent:Clone()
		plant.Parent = player.Character
	end
end)

Other than that though, what issues are you having?

What do you exactly mean when make sure there a character instead of useless part?

also I got this error saying Propers team is not a valid member of teams

Well, when the ClickDetector is clicked, it may be possible for the player who clicked to not have a character. This is an issue because you’d just be creating new parts and parenting them to nil (because the player has no character, meaning Player.Character is nil which may increase server load/lag.

Have you tried creating a ‘Team’ under the ‘Teams’ service/category in the Explorer panel with the name ‘Propers’ and setting the ‘AutoAssignable’ property to true in the Properties panel?

If you talking about exactly the Team name yes I did second of all what does AutoAssignable exactly do.

also it was enabled the whole time

If you did place the team in the Teams service, the script must have the wrong name.

AutoAssignable just makes it so when a player joins, their team can be automatically set to that team.

What was enabled?

the auto assignable was enabled

Alright, are there any errors you’re currently experiencing still?

Well I still not turning to the object when im in the exact team and when I click on this object.

You’ll have to write your own functionality to change your humanoid to control whatever part they clicked on.

ok I will try to do that hopefully this post of yours helps

1 Like

Update the good news is my script is working but bad news is not the way you think you see is cloning the part instead making the player into the part

I try to put humanoidRootPart and humanoid still looking into it

You just want your character to change? (Make sure the plant has a humanoid and a root part)

local plant = script.Parent:Clone()
plant.Name = plr.Name
player.Character = plant
plant.Parent = workspace
— Optionally you can make it so the name can’t be viewed with Humanoid.NameDisplayDistance

Yeh I done that but now I don’t know how to properly put my CFrame there was one but it was deprecated

local teams = game:GetService("Teams")
local clickDetector = script.Parent.ClickDetector
local model = script.Parent
-- everytime the MouseClick event fires, it fires the player who clicked with it
clickDetector.MouseClick:Connect(function(player)
	
	-- also make sure they have a character instead of creating useless parts
	if player.Team == teams.Propers and player.Character then
		wait()
		local oldCharacter = player.Character
		local morphModel = model:FindFirstChildOfClass("Model")
		local newCharacter = morphModel:Clone()
		player.Character = newCharacter
		newCharacter.Parent = game.Workspace
	end
end)

Im not really sure if i ment to rigg the plant or something