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

Putting Charactermesh on player?

Hi guys! I am trying to create a script that checks if the players is on the bright blue team and if they are then removes a charactermesh and replaces it with one from the workspace...although it isn't quite working or complete - any help would be greatly appreciated. Thanks :)

This is what I have so far, although it doesn't remove the old charactermesh and doesn't work :D

local TeamColor = BrickColor.new("Bright blue") 

local Player = game:GetService("Players").LocalPlayer
local function Check()

local mesh = game.Workspace.AgentLeftArm:Clone()
mesh.Parent = Player

end Player.Changed:connect(Check)

2 comments

0

If you provide the output, if any, that could really help us help you! Also, is this a local script?

0

Yes, this is a localscript - and I don't seem to be getting any output :(

1 answer

✓ Accepted answer

What you have set up right now inserts a new clone of AgentLeftArm in Workspace every time ANY property of the Player is changed. You are looking to see if a specific property [TeamColor] is changed to a specific value [BrickColor.new("Bright blue")].

local player = game.Players.LocalPlayer
local teamColor = BrickColor.new("Bright blue")

player.Changed:connect(function(property)
	if property == "TeamColor" then
		if player.TeamColor == teamColor then
			local mesh = game.Workspace.AgentLeftArm:Clone()
			mesh.Parent = player.Character
			-- What ever else you want here
		end
	end
end)

But if I character respawns, the TeamColor property doesn't change. If you want to insert it into the character if it spawns in on the Bright blue Team then you'll need to have a CharacterAdded function as well.

local player = game.Players.LocalPlayer
local teamColor = BrickColor.new("Bright blue")

player.CharacterAdded:connect(function()
	if player.TeamColor == teamColor then
		repeat wait() until character:FindFirstChild("Humanoid")
		local mesh = game.Workspace.AgentLeftArm:Clone()
		mesh.Parent = player.Character
		-- What ever else you want here
	end	
end)

player.Changed:connect(function(property)
	if property == "TeamColor" then
		if player.TeamColor == teamColor then
			local mesh = game.Workspace.AgentLeftArm:Clone()
			mesh.Parent = player.Character
			-- What ever else you want here
		end
	end
end)

EDIT FIXED

local teamColor = BrickColor.new("Bright blue")

game.Players.PlayerAdded:connect(function(player)
	player.CharacterAdded:connect(function(character)
		if player.TeamColor == teamColor then
			repeat wait() until character:FindFirstChild("Humanoid")
			local mesh = game.Workspace.AgentLeftArm:Clone()
			mesh.Parent = character
			-- What ever else you want here
		end	
	end)
	
	player.Changed:connect(function(property)
		if property == "TeamColor" then
			if player.TeamColor == teamColor then
				local mesh = game.Workspace.AgentLeftArm:Clone()
				mesh.Parent = player.Character
				-- What ever else you want here
			end
		end
	end)
end)

9 comments

0

Thank you SO much :) Just a question - where would you put this script?

0

Looking over this now, I would suggest putting this in a regular script: See the edit.

0

Thanks! A regular script just in the workspace? Or in the players starterpack?

0

In the Workspace or ServerScriptStorage, which ever your preference.

0

Thanks, but it still doesn't work? Maybe we have to destroy the current Charactermesh that is on the player first?? :)

0

Yeah that is someone you'd need to do, put all the personalized stuff at the 'What ever else you want here' spot

0

As a note, testing this is Test mode will not work unless you open up a test server as the player loads before the script does.

1

Whoops, the mesh is being parented to the player not the character, did look over your code good enough

0

Thank you very much for all your help :)

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