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)
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?
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?
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)