I have been programming a game called Frenzy Sprint. One of the items you can buy in a shop is a trail, but all of a sudden the code that unequips the trails stopped working. It literally worked a couple hours ago, but now clicking “unequip” does absolutely nothing on the server side. When I look at what’s going on in the Workspace, the trails go away for about half of a second and then come right back.
The system of equipping/unequipping (Idk if “unequipping” is a word, but I’ll use it anyway ) items works this way:
- A bool value determines whether the equip button should function as an “equip” or “unequip” button
- Equip section works, so I won’t describe
- Unequip section invokes a RemoteFunction; code will be explained
- If RemoteFunction returns true, the equip button will display that
The issue is that it returns true, but the items come back after a very short period of time. So essentially the RemoteFunction runs its course but the trails just come back almost right away.
I have a couple trails in the store, but I’ll use the Blue trail as an example. Here is the code inside of the LocalScript (a child of the Equip button):
local equipped = script.Parent.Parent.Equipped script.Parent.Activated:Connect(function() if equipped.Value == false then local equip = game:GetService("ReplicatedStorage"):FindFirstChild("EquipTrail"):InvokeServer("Blue") if equip == true then --This section works; deleted code in the forum for brevity end else local unequip = game:GetService("ReplicatedStorage"):FindFirstChild("UnequipTrail"):InvokeServer("Blue") if unequip == true then --If it returns true, that means it was successful equipped.Value = false script.Parent.Text = "Equip" end end end)
In ServerScriptService, I took out a snippet of the code that refers to destroying, equipping, and unequipping the blue trail:
local function destroyAllTrails(player) local char = player.Character if char.Head:FindFirstChild("BlueTrail") ~= nil then char.Head.BlueTrail:Destroy() char.Head.TrailAttachment0:Destroy() char.HumanoidRootPart.TrailAttachment1:Destroy() end end
Equipping the trail:
game.ReplicatedStorage.EquipTrail.OnServerInvoke = function(player, trailColor) if trailColor == "Blue" then destroyAllTrails(player) local char = player.Character local ServerStorage = game.ServerStorage.BlueTrail:Clone() ServerStorage.Parent = char.Head local attachment0 = Instance.new("Attachment",char.Head) attachment0.Name = "TrailAttachment0" local attachment1 = Instance.new("Attachment",char.HumanoidRootPart) attachment1.Name = "TrailAttachment1" ServerStorage.Attachment0 = attachment0 ServerStorage.Attachment1 = attachment1 return true end end
And… last but not least, unequipping the trails:
game.ReplicatedStorage.UnequipTrail.OnServerInvoke = function(player, trailColor) local char = player.Character if trailColor == "Blue" then if char.Head:FindFirstChild("BlueTrail") ~= nil then char.Head.BlueTrail:Destroy() char.Head.TrailAttachment0:Destroy() char.HumanoidRootPart.TrailAttachment1:Destroy() return true end end end
So far, I’ve tried reverting the version to a version before the issue happened, but there was no success. There were tons of different things I tried, but nothing worked. I also looked up Remove() but apparently it’s now deprecated so that probably wouldn’t work. If anyone could help me out with this, I would really appreciate it. Thanks in advance!