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

Why isn't my /msg function working with adding an accessory?

Asked by
JipSea 23
3 years ago

Hello! I am trying to create a /msg function that will allow players to type a specific command and wear the designated accessory in game.

I have a RemoteEvent in Replicated Storage called "Silver3"

Inside "ServerScriptService" I have a script:

local ins = game:GetService("InsertService")
local e = game.ReplicatedStorage.Silver3

local silv3 = ins:LoadAsset(439945661)
silv3.Parent = game.ReplicatedStorage
silv3.Name = "silv3"


local function AddCustomAccessory(Model, Accessory)
    Accessory.Parent = Model
    local HandleAttachment = Accessory.Handle:FindFirstChildOfClass("Attachment") -- Find accessory attachment
    local CharacterAttachment do -- Find character attachment
        for _, v in ipairs(Model:GetDescendants()) do
            if v.Name == HandleAttachment.Name and not v:FindFirstAncestorOfClass("Accessory") then
                CharacterAttachment = v
                break
            end
        end
    end

    --| Destroy any previous welds.
    for _, v in ipairs(Model:GetDescendants()) do
        if v.ClassName == "Weld" and v.Name == "AccessoryWeld" then
            v:Destroy()
        end
    end

    --| Replace the weld with a Motor6D instead.
    local AttachmentWeld = Instance.new("Motor6D")
    AttachmentWeld.Part0 = CharacterAttachment.Parent
    AttachmentWeld.Part1 = HandleAttachment.Parent
    AttachmentWeld.C0 = CharacterAttachment.CFrame
    AttachmentWeld.C1 = HandleAttachment.CFrame
    AttachmentWeld.Name = Accessory.Name
    AttachmentWeld.Parent = Accessory
end

and inside "StarterPlayer" / "StarterPlayerScripts" I have a LocalScript:

local player = game.Players.LocalPlayer
local char = game.Workspace:WaitForChild(player.Name)
local e = game.ReplicatedStorage.Silver3

local hasSilver3 = false


player.Chatted:Connect(function(msg)
    if msg:lower() == "/silver" and hasSilver3 == false then
        char.Humanoid:SetStateEnabled("Dead", false)
        e:FireServer()
        hasSilver3 = true
    end
end)

e.OnClientEvent:Connect(function()
    char.Humanoid:SetStateEnabled("Dead",true)
end)

player.CharacterAdded:Connect(function()
    if hasSilver3 == true then
        hasSilver3 = false
    end
end)

Any ideas or suggestions as to why it is not working?

I am attempting to have the player type /silver in chat to make them wear https://www.roblox.com/catalog/439945661/Silver-King-of-the-Night

Any help would be appreciated.

THANK YOU!

0
Bump JipSea 23 — 3y

Answer this question