Hello! I've been working at some abilities for a while, using RemoteEvents to work both with the server and the client, but I've encountered multiple issues, and I think the main issue might be using Loops inside the function? I'm really not sure, any help would be appreciated!
As you can see, this code should summon 2 slicers near the character's shoulder (WS1 and WS2), and then go to the mouse's position. If they touch any player, that player will take damage and an explosion will happen. The problem is that WS2 won't get cloned, along with the rest of the script not working at all.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Events = ReplicatedStorage.Events
local Player = game.Players.LocalPlayer
local near_character = true
local near_character2 = true
function ws_position(Player,variable, x, value)
while variable do
x.Position = Player.Character.HumanoidRootPart.Position + Vector3.new(value, 4, 0)
wait(0.001)
end
end
Events.WaterSaucers.OnServerEvent:Connect(function(Player, mousePos)
local character = Player.Character
local WS1 = ReplicatedStorage.WaterSaucerParts.WS1:Clone()
WS1.Parent = workspace
WS1.Position = Player.Character.HumanoidRootPart.Position + Vector3.new(3, 0, 0)
local bp = Instance.new("BodyPosition")
bp.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
bp.Parent = WS1
ws_position(Player, near_character, bp, 3)
wait(1)
local WS2 = ReplicatedStorage.WaterSaucerParts.WS2:Clone()
WS2.Parent = workspace
WS2.Position = Player.Character.HumanoidRootPart.Position + Vector3.new(-3, 0, 0)
local bodyp2 = Instance.new("BodyPosition")
bodyp2.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
bodyp2.Parent = WS2
ws_position(Player, near_character2, bodyp2, -3)
wait(0.1)
near_character = false
near_character2 = false
bp:Destroy()
bodyp2:Destroy()
wait(0.01)
local BV1 = Instance.new("BodyVelocity")
BV1.Parent = WS1
BV1.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
BV1.Velocity = CFrame.new(WS1.Position, mousePos).lookVector * 50
local BV2 = Instance.new("BodyVelocity")
BV2.Parent = WS2
BV2.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
BV2.Velocity = CFrame.new(WS2.Position, mousePos).lookVector * 50
WS1.Touched:Connect(function(hit)
if hit:IsDescendantOf(character) then return end
local explosion = game.ReplicatedStorage.WaterSaucerParts.Explosion:Clone()
explosion.Parent = workspace
explosion.Position = WS1.Position
WS1:Destroy()
if hit.Parent:FindFirstChild("Humanoid") then
hit.Parent:FindFirstChild("Humanoid"):TakeDamage(15)
wait(1)
explosion:Destroy()
end
end)
WS2.Touched:Connect(function(hit)
if hit:IsDescendantOf(character) then return end
local explosion = game.ReplicatedStorage.WaterSaucerParts.Explosion:Clone()
explosion.Parent = workspace
explosion.Position = WS2.Position
WS2:Destroy()
if hit.Parent:FindFirstChild("Humanoid") then
hit.Parent:FindFirstChild("Humanoid"):TakeDamage(15)
wait(1)
explosion:Destroy()
end
end)
wait(2)
WS1:Destroy()
WS2:Destroy()
end)
To anyone helping me, thank you so much. I really appreciate it! I'm still learning so I know I have a long way before I could name myself a scripter. I also apologize for any formatting mistakes in the code! I've made sure to use the correct amount of spaces in studio but for some reason it might not look the same when you check my question.
