Hey, I was working on stun rocks that stun the player. I tested the stun script and it works and now I just have to clone the script into the rocks that are created. Problem is when I try to clone the script in to the rocks it doesn’t work, but when I clone a sound to an part, it works.
Here’s the function I call
function StraightStunRocks(root,player)
local parms = RaycastParams.new()
parms.FilterDescendantsInstances = {workspace.Ability.Debris,characters}
parms.FilterType = Enum.RaycastFilterType.Blacklist
local angle = 0
local extraheight = 0
local cf = player.Character.HumanoidRootPart.CFrame
-- Creating Rocks
for i = 1,4 do
local size = math.random(4,7)
local height = 5
local part = Instance.new("Part")
local sound = Instance.new("Sound")
local stun = script.Stun:Clone()
stun.Parent = part
stun.Enabled = true
sound.Parent = part
sound.SoundId = "rbxassetid://9125869138"
sound.RollOffMaxDistance = 200
sound.RollOffMinDistance = 6
sound.Volume = 1.2
local lv = player.Character.HumanoidRootPart.CFrame.LookVector
local direction = player.Character.HumanoidRootPart.Position + (lv * ((i+1) * (2.5 + i)))
-- Properties
part.Anchored = true
part.Size = Vector3.new(1,1,1)
part.CFrame = player.Character.HumanoidRootPart.CFrame
game.Debris:AddItem(part,5)
game.Debris:AddItem(stun,4)
local raycast = workspace:Raycast(part.CFrame.p,part.CFrame.UpVector * -15, parms)
if raycast then
part.CanCollide = false
part.Material = Enum.Material.Rock
part.BrickColor = BrickColor.new("Brown")
part.Position = direction + Vector3.new(0,-5,0)
part.Size = Vector3.new(8,height + extraheight,8)
part.Orientation = Vector3.new(part.Orientation.X,math.random(-180,180),part.Orientation.Z)
part.Parent = workspace.Ability.Debris
sound:Play()
local Tween = game:GetService("TweenService"):Create(part,TweenInfo.new(.25,Enum.EasingStyle.Bounce,Enum.EasingDirection.Out),{Position = part.Position + Vector3.new(0,5,0)}):Play()
delay(4,function()
local Tween = game:GetService("TweenService"):Create(part,TweenInfo.new(1),{Transparency = 1}):Play()
end)
end
print(extraheight)
extraheight += 4
wait(0.2)
end
end
Stun Script
repeat wait(0.2) until script.Parent:IsA("Part")
local part = script.Parent
local gui = script.StunGUI
local anim = Instance.new("Animation")
anim.AnimationId = "rbxassetid://11273357512"
anim.Parent = script
local function Stun(player)
local hum = player.Character:FindFirstChild("Humanoid")
if anim then
StunAnim = hum:LoadAnimation(anim)
end
gui.ImageLabel.ImageTransparency = 1
local guiClone = gui:Clone()
guiClone.Parent = hum.Parent:FindFirstChild("HumanoidRootPart")
local guiTween = game.TweenService:Create(guiClone.ImageLabel,TweenInfo.new(0.5,Enum.EasingStyle.Sine,Enum.EasingDirection.Out),{ImageTransparency = 0})
local guiFade = game.TweenService:Create(guiClone.ImageLabel,TweenInfo.new(0.5,Enum.EasingStyle.Sine,Enum.EasingDirection.Out),{ImageTransparency = 1})
local Stun = Instance.new("BoolValue")
Stun.Name = "Stun"
Stun.Parent = player
guiTween:Play()
StunAnim:Play()
hum.WalkSpeed = 0
hum.JumpPower = 0
game.Debris:AddItem(Stun,4)
wait(4)
guiFade:Play()
StunAnim:Stop()
hum.WalkSpeed = 16
hum.JumpPower = 50
end
local deb = false
part.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid",true) then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
print("found")
if not player:FindFirstChild("Stun") and not deb then
deb = true
print("stunning...")
Stun(player)
deb = false
end
end
end)
Explorer:
Thanks for reading (Please help)