So, I have a skateboard spawner GUI made, which works perfectly fine but has a little bug where it does more than just spawn the skateboard. It drops a little baby one as well.
I don’t even know what is causing this bug. I can post source code provided below:
-- This is the local "call" script:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local SkateboardEvent = ReplicatedStorage:WaitForChild("Skateboard")
local Skateboard = script.Parent.Name
local SkateboardSpawner = script.Parent
local cooldown = 5
local spawncooldown = false
local skateboardName = Players.Name.."'s Skateboard"
local plr = Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
local currentSkateboard = game.Workspace:FindFirstChild(skateboardName) or plr.Character:FindFirstChild(skateboardName)
if currentSkateboard or spawncooldown == false then
SkateboardSpawner.ImageTransparency = 0
SkateboardEvent:FireServer('Skateboard')
if not currentSkateboard and spawncooldown == false then
spawncooldown = true
wait(cooldown)
spawncooldown = false
end
end
end)
-- This is the Server script which spawns the skateboard.
local ServerStorage = game:GetService("ServerStorage")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SkateboardEvent = game.ReplicatedStorage:WaitForChild("Skateboard")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local SkateboardEvent = ReplicatedStorage:WaitForChild("Skateboard")
local Skateboard = script.Parent.Name
local SkateboardSpawner = script.Parent
local cooldown = 5
local spawncooldown = false
local plr = Players.LocalPlayer
local skateboardName = Players.Name.."'s Skateboard"
local db = false
SkateboardEvent.OnServerEvent:Connect(function(player, Skateboard)
local skateboardName = player.Name.."'s Skateboard"
local currentSkateboard = game.Workspace:FindFirstChild(player.Name.."'s Skateboard") or player.Character:FindFirstChild(player.Name.."'s Skateboard")
if currentSkateboard then
currentSkateboard.SkateboardPlatform.PlatformMotor6D:Destroy()
currentSkateboard.Parent.Humanoid.PlatformStand = false
currentSkateboard:Destroy()
else
local clonedSkateboard = ServerStorage:FindFirstChild("Skateboard"):Clone()
clonedSkateboard:MakeJoints()
clonedSkateboard.Name = player.Name.."'s Skateboard"
clonedSkateboard.Parent = game.Workspace
clonedSkateboard:SetPrimaryPartCFrame(player.Character.HumanoidRootPart.CFrame + Vector3.new(0,0,5))
end
end)