Basically, I have a working skateboard spawner, but for some reason whenever someone spawns ingame, it auto dismounts people and sometimes when someone spawns a board, it makes everyone else spawn a skateboard.
Local:
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)
script.Parent.MouseEnter:Connect(function()
script.parent.ImageTransparency = 0
script.Parent.ImageColor3 = Color3.fromRGB(255, 255, 255)
end)
script.parent.MouseLeave:Connect(function()
script.Parent.ImageTransparency = 0.5
script.Parent.ImageColor3 = Color3.fromRGB(255,255,255)
end)
SERVER:
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 skateboardName = Players.Name.."'s Skateboard"
SkateboardEvent.OnServerEvent:Connect(function(player, Skateboard)
local skateboardName = player.Name.."'s Skateboard"
local spawnedBoard = game.Workspace:FindFirstChild(player.Name.."'s Skateboard")
local currentSkateboard = player.Character:FindFirstChild(player.Name.."'s Skateboard")
if spawnedBoard then -- Check to see if skateboard is spawned in game if so, then destroy
spawnedBoard:Destroy()
elseif currentSkateboard then -- check to see if skateboard is mounted, if so, then dismount
currentSkateboard.SkateboardPlatform.PlatformMotor6D:Destroy()
currentSkateboard.Parent.Humanoid.PlatformStand = false
currentSkateboard:Destroy()
else
local clonedSkateboard = ServerStorage:FindFirstChild("Skateboard"):Clone() -- if no skateboard is spawned, spawn one
clonedSkateboard:MakeJoints()
clonedSkateboard.Name = player.Name.."'s Skateboard"
clonedSkateboard.Parent = game.Workspace
clonedSkateboard:SetPrimaryPartCFrame(player.Character.HumanoidRootPart.CFrame + Vector3.new(0,0,0))
end
end)
Am I missing something in this?