Add PlatForm function when tool is activated?

Hi everyone I’m currently working on an Ability Tool System and rn I want that if I activate my Tool a Part/platformTemplate should appear where I clicked with my Mouse with a duration and cooldown rn I have a script and I have put the platformTemplate in the Replicated Storage and I’m not sure uf I did anything wrong or something is missing pls help

local debounce = true -- While this value is true the platform can be created
local mouse = game.Players.LocalPlayer:GetMouse()
local platformTemplate = game.ReplicatedStorage.platformTemplate

local function createPlatform()
	if not debounce then
		return
	end

	debounce = false -- Can't use the platform again until this changes back to true
	local platform = platformTemplate:Clone()
	platform.Position = mouse.Hit.p -- Positions the platform where you clicked
	platform.Parent = workspace
	task.wait(5)
	platform:Destroy()

	task.delay(4, function() -- Adjust the number here for the cooldown length
		debounce = true
	end)
end
2 Likes