So I made a radio tool and when you equip it, you can click with your mouse once and the animation + sound will play. There is also a “fake” accessory type of radio on the back of the player. When the tool is equipped, the accessory disappears, but when they unequip it, it should reappear but it doesn’t.
Problem 1: After I unequip it and equip it another time, the tool just disappears from my tool bar. Problem 2: The “accessory” doesn’t show up again on the player’s back but it was there before they equipped it.
Video
Local Script inside the Tool:
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local db = false
local db = false
script.Parent.Equipped:Connect(function()
if db ==false then
db = true
game.ReplicatedStorage.AccessoryDelete:FireServer()
mouse.Button1Down:Connect(function()
game.ReplicatedStorage.RadioEvent:FireServer("7682535846")
script.Parent.RadioStatic:Play()
wait(3.80)
script.Parent.RadioStatic:Stop()
db = false
end)
else
return
end
end)
script.Parent.Unequipped:Connect(function()
if db == false then
if script.Parent.Equipped == false then
db = true
game.ReplicatedStorage.AccessoryAdd:FireServer()
wait(3)
db = false
end
end
end)
Accessory script inside StarterCharacterScripts:
local Radio = game.ServerStorage.Radio:Clone()
local humanoid = script.Parent:FindFirstChild("Humanoid")
local function createAccessory()
humanoid:AddAccessory(Radio)
end
local function deleteAccessory(player)
player.Character:FindFirstChild("Radio"):Destroy()
end
createAccessory()
game.ReplicatedStorage.AccessoryAdd.OnServerEvent:Connect(function()
createAccessory()
end)
game.ReplicatedStorage.AccessoryDelete.OnServerEvent:Connect(function(player)
deleteAccessory(player)
end)
Animation Script:
game.ReplicatedStorage.RadioEvent.OnServerEvent:Connect(function(player, animationID)
local animation = Instance.new("Animation")
animation.AnimationId = "https://www.roblox.com/Asset?ID="..animationID
local loadedAnimation = game.Workspace[player.Name].Humanoid:LoadAnimation(animation)
loadedAnimation:Play()
wait(3.80)
loadedAnimation:Stop()
end)
Can anybody help? I know it’s a lot of scripts but I just wanna know whats goin on because I’m also not getting any errors in my output either. AHH. Scripting problems lol.
So, i’m assuming that there’s no errors in the output, but make sure that you don’t accidentally call deleteAccessory() in your code. I searched the code, and i reckon it might have something to do with this line:
i am not realy familiar with :AddAccessory. but another way to achieve the same effect is just to put the Transparency to 1 when you want to delete it and back to 0 when you want to put it back. this will create the illusion of it being taken of and put back.
The functions in your accessory script would become this
local function createAccessory()
player.Character:FindFirstChild("Radio").Transparency = 0
end
local function deleteAccessory(player)
player.Character:FindFirstChild("Radio").Transparency = 1
end
The Radio variable you made is a constant. Meaning it will only clone the radio tool once.
The second time you equip it, its not there because the radio has already been destroyed.
Change it to:
local Radio = game.ServerStorage.Radio
local function createAccessory()
humanoid:AddAccessory(Radio:Clone())
end
This worked and the tool isn’t disappearing after the second time I unequip it, but when I equip it for the second time, the accessory doesn’t show up on the back of the player (but it did when they joined).
local Radio = game.ServerStorage.Radio
local humanoid = script.Parent:FindFirstChild("Humanoid")
local function onStartUp()
humanoid:AddAccessory(Radio:Clone())
end
local function createAccessory(player)
player.Character:FindFirstChild("Radio").Handle.Transparency = 0
end
local function deleteAccessory(player)
player.Character:FindFirstChild("Radio").Handle.Transparency = 1
end
onStartUp()
game.ReplicatedStorage.AccessoryAdd.OnServerEvent:Connect(function()
createAccessory()
end)
game.ReplicatedStorage.AccessoryDelete.OnServerEvent:Connect(function(player)
deleteAccessory(player)
end)
@HafiyNufail and @trissie224 are right, you are cloning the radio only on the start, but you need to clone it every time you will add the accessory. So you can either do
local Radio = game.ServerStorage.Radio
local function createAccessory()
humanoid:AddAccessory(Radio:Clone())
end
or
local Radio = game.ServerStorage.Radio
local function createAccessory()
local RadioClone = Radio:Clone()
humanoid:AddAccessory(RadioClone)
end
I successfully made a script, with @trissie224 's idea to clone the radio at the start but automatically make it transparent and if the player is on the police team, the radio’s transparency is 0. Here is the script I used for reference. Thanks to everyone who helped!
local Radio = game.ServerStorage.RadioAccessory
local humanoid = script.Parent:FindFirstChild("Humanoid")
local function onStartUp()
humanoid:AddAccessory(Radio:Clone())
end
local function createAccessory()
humanoid.Parent:FindFirstChild("RadioAccessory").Handle.Transparency = 0
end
local function deleteAccessory()
humanoid.Parent:FindFirstChild("RadioAccessory").Handle.Transparency = 1
end
onStartUp()
deleteAccessory()
game.ReplicatedStorage.AccessoryAdd.OnServerEvent:Connect(function(player)
createAccessory(player)
end)
game.ReplicatedStorage.AccessoryDelete.OnServerEvent:Connect(function(player)
deleteAccessory(player)
end)
game.Teams.Police.PlayerAdded:Connect(function(player)
print(player.Name.." has joined the police team")
createAccessory()
local radioTool = game.ServerStorage.Radio:Clone()
radioTool.Parent = player.Backpack
end)