Hello, I made a trail shop (GUI fully working) and trails already made but I’m having problems with equipping the trails, so for example if I click a button for the trail that costs 300 coins, the coins are removed from the balance of the player but the trail doesn’t appear (video below) and gives no error in output.
The trails are in a folder named “Trails” in ServerStorage.
Below I’m leaving the scripts:
TrailHandler This should handle all of the trails, inside of ReplicatedStorage I have placed a RemoteEvent named “EquipTrail”
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Trails = ReplicatedStorage.Trails
local EquipTrail = ReplicatedStorage.EquipTrail
EquipTrail.OnServerEvent:Connect(function(player, trail)
local character = player.Character
if not character:FindFirstChild(trail) then
for i,v in pairs(character:GetChildren()) do
if v:IsA("Trail") then
v:remove()
end
end
local trailCopy = Trails[trail]:Clone()
trailCopy.Parent = character
trailCopy.Attachment0 = character.Head.At1
trailCopy.Attachment1 = character.HumanoidRootPart.At2
end
end)
Leaderstats that controls the jumps and coins. From line 59 to 68 there is the function regarding the trails.
local DataStoreService = game:GetService("DataStoreService")
local jumpsDatastore = DataStoreService:GetDataStore("JumpsDataStore")
local function loadData(datastore, key)
local success, data = pcall(function()
return datastore:GetAsync(key)
end)
return data
end
local function saveData(datastore, key, value)
local success, err = pcall(function()
datastore:SetAsync(key, value)
end)
if err then print(err) end
end
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local jumpCount = Instance.new("IntValue")
jumpCount.Name = "Jumps"
jumpCount.Parent = leaderstats
jumpCount.Value = loadData(jumpsDatastore, player.UserId) or 0
local coins = Instance.new("NumberValue")
coins.Parent = player.leaderstats
coins.Name = "Coins"
player.CharacterAdded:Connect(function(character)
local humanoid = character:WaitForChild("Humanoid")
local debounce = true
humanoid:GetPropertyChangedSignal("Jump"):Connect(function()
if debounce == true then
debounce = false
if humanoid.Jump == true then
jumpCount.Value = jumpCount.Value + 1
end
wait(0.2)
debounce = true
end
end)
end)
end)
game.Players.PlayerRemoving:Connect(function(player)
local jumps = player.leaderstats.Jumps
saveData(jumpsDatastore, player.UserId, jumps.Value)
end)
game.Players.PlayerAdded:Connect(function(NewPlayer)
NewPlayer.CharacterAdded:Connect(function()
local character = NewPlayer.Character
local At1 = Instance.new("Attachment", character:WaitForChild("Head"))
local At2 = Instance.new("Attachment", character:WaitForChild("HumanoidRootPart"))
At1.Name = "At1"
At2.Name = "At2"
end)
end)
ShopHandler This should control how the shop works
local HolderFrame = script.Parent.Holder
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Trails = ReplicatedStorage.Trails
local EquipTrail = ReplicatedStorage.EquipTrail
local player = game.Players.LocalPlayer
local character = player.Character
if not character or not character.Parent then
character = player.CharacterAdded:wait()
end
for i,v in pairs(HolderFrame:GetChildren()) do
if v:IsA("TextButton") then
v.MouseButton1Click:Connect(function()
if v.Purchased.Value == false then
if player.leaderstats.Coins.Value >= v.Cost.Value then
player.leaderstats.Coins.Value = player.leaderstats.Coins.Value - v.Cost.Value
v.Purchased.Value = true
v.Status.Text = "Purchased"
else
print("Not Enough")
end
elseif v.Purchased.Value == true then
local trail = v.Name
EquipTrail:FireServer(trail)
end
end)
end
end
I want to find a solution of this problem as I’ve been brainstorming for about 8 hours and still can’t find anything
Sorry in advance for the many scripts and requests.
Thanks to everyone that tries to help