local TweenService = game:GetService("TweenService")
local MovingObs = game.Workspace:FindFirstChild("MovingObstacles")
local spikeFolder = MovingObs:WaitForChild("SpikeTrap")
local spikesModel = spikeTrap:WaitForChild("Spikes")
local function tweenSpikeModel(spike)
local CF_v = Instance.new("CFrameValue")
CF_v.Changed:Connect(function(V)
spike:SetPrimaryPartCFrame(V)
end)
CF_v.Value = spike:GetModelCFrame()
local tweenInfo = TweenInfo.new(2, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut, -1, true)
local endCFrame = spike:GetModelCFrame() + Vector3.new(0, -6, 0)
local tween = TweenService:Create(CF_v, tweenInfo, {Value = endCFrame})
tween:Play()
end
local function onSpikeTouch(hit)
local char = hit.Parent
local humanoid = char:FindFirstChild("Humanoid")
if humanoid then
humanoid:TakeDamage(50)
end
end
for _, spike in ipairs(spikesModel:GetChildren()) do
if spike:IsA("Model") then
tweenSpikeModel(spike)
for _, part in ipairs(spike:GetChildren()) do
if part:IsA("BasePart") then
part.Touched:Connect(onSpikeTouch)
end
end
end
end
I used WeldConstraints for my other obstacle, Im trying to do the same thing with my spikes, for some reason, only the primary part moves, but the other parts i welded to the primary do not work properly.
local TweenService = game:GetService("TweenService")
local model = game.Workspace:WaitForChild("Spike")
local primaryPart = model.PrimaryPart
if not primaryPart then
print("no primary")
return
end
local tweenInfo = TweenInfo.new(
2,
Enum.EasingStyle.Sine,
Enum.EasingDirection.InOut,
-1,
true
)
local startPosition = primaryPart.Position
local targetPosition = startPosition + Vector3.new(0, 4, 0)
local goal = {Position = targetPosition}
local tween = TweenService:Create(primaryPart, tweenInfo, goal)
tween:Play()local TweenService = game:GetService("TweenService")
local model = game.Workspace:WaitForChild("Spike")
local primaryPart = model.PrimaryPart
if not primaryPart then
print("no primary")
return
end
local tweenInfo = TweenInfo.new(
2,
Enum.EasingStyle.Sine,
Enum.EasingDirection.InOut,
-1,
true
)
local startPosition = primaryPart.Position
local targetPosition = startPosition + Vector3.new(0, 4, 0)
local goal = {Position = targetPosition}
local tween = TweenService:Create(primaryPart, tweenInfo, goal)
tween:Play()
Video of the spike:
If you’d like more information, please let me know
Only the tweened Part should be anchored. Anything else has to be unanchored.
If they are in the baseplate you may need to put the baseplate (or other obby parts) and the spikes in a CollisionGroup that doesn’t collide with itself.
woops, accidentally clicked solution, the main game idea is a car obby, meaning that I will need many spikes to do that, might aswell make it simple to make the damage part like that so i dont have to find children in the model and give them each the damage ability
For that you could use Tags or Attributes in each of the spikes.
Please read all the questions and suggestions in a post. I’ve seen a couple of items that you haven’t confirmed.
@puffo suggested prints (print variables or items like goal, not just “this worked” or “moved”).
I suggested making all the Parts CanCollide false in my previous post.
Also are you sure your welds are active? In the Model tab under Constraints click the Show Welds button. There should be green weld lines running between unanchored items. Grey lines indicate items welded to an anchored item. If there are no visual welds then click the Part0 and Part1 in the WeldConstraint Properties and reclick each Part they are supposed to be joined to.