Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Putting Charactermesh on player?

Asked by 10 years ago

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)
0
If you provide the output, if any, that could really help us help you! Also, is this a local script? Necrorave 560 — 10y
0
Yes, this is a localscript - and I don't seem to be getting any output :( jjwood1600 215 — 10y

1 answer

Log in to vote
1
Answered by
BlackJPI 2658 Snack Break Moderation Voter Community Moderator
10 years ago

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)
0
Thank you SO much :) Just a question - where would you put this script? jjwood1600 215 — 10y
0
Looking over this now, I would suggest putting this in a regular script: See the edit. BlackJPI 2658 — 10y
0
Thanks! A regular script just in the workspace? Or in the players starterpack? jjwood1600 215 — 10y
0
In the Workspace or ServerScriptStorage, which ever your preference. BlackJPI 2658 — 10y
View all comments (5 more)
0
Thanks, but it still doesn't work? Maybe we have to destroy the current Charactermesh that is on the player first?? :) jjwood1600 215 — 10y
0
Yeah that is someone you'd need to do, put all the personalized stuff at the 'What ever else you want here' spot BlackJPI 2658 — 10y
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. BlackJPI 2658 — 10y
1
Whoops, the mesh is being parented to the player not the character, did look over your code good enough BlackJPI 2658 — 10y
0
Thank you very much for all your help :) jjwood1600 215 — 10y
Ad

Answer this question