I saw that code works with Touched event but didn’t work with ClickDetector. Did you look for solutions on the Developer Hub?
I hope somebody know more codes than me, for see some problem in my code for help me.
-- This is an example Lua code block
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.
According to the developer reference API the click detector event returns a player instance and not the part of the character which is only applicable for Touched events.
Consequently, you can get the player’s character Humanoid root part by getting the players character instead:
local humanoidRootPart = clicked.Character.HumanoidRootPart
local DestinatonPart = workspace.Destination
local Cooldown = 3
local CooldownVar = false
script.Parent.Parent.Color = Color3.fromRGB(0,137,0)
script.Parent.MouseClick:Connect(function(Player)
if CooldownVar then return end
CooldownVar = true
script.Parent.Parent.Color = Color3.fromRGB(255,0,0)
script.Parent.MaxActivationDistance = 0
local Character = Player.Character
if Character then
local HumanoidRootPart = Character:FindFirstChild("HumanoidRootPart")
if HumanoidRootPart then
HumanoidRootPart.CFrame = DestinatonPart.CFrame + Vector3.new(0, 10, 0)
wait(Cooldown)
end
end
script.Parent.Parent.Color = Color3.fromRGB(0,137,0)
script.Parent.MaxActivationDistance = 32
CooldownVar = false
end)