Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

server script loops doesn't function correctly. how do i use loops in this situation?

so basically, i have a localscript that uses a key function to fireserver to a remoteevent. and when this event is recieved from the server script, it is suppose to create a ball that increases sizes then eventually dissapears.

however, with my minimal knowledge of loops, i cannot understand how to do this. can someone tell me what's wrong with this loop script?

SERVER SCRIPT: (this is where the issue lies)

local tEvent = Instance.new("RemoteEvent")
tEvent.Name = "tEvent"
tEvent.Parent = script.Parent.Parent.Parent.ReplicatedStorage

tEvent.OnServerEvent:Connect(function(Player) -- Player who fired the event

    local Character = Player.Character or Player.CharacterAdded:wait()

-- animation

local humanoid = Character.Humanoid

local animation = script.Animation

local animtrack = humanoid:LoadAnimation(animation)
animtrack:Play()

wait(.4)

local swave = Instance.new("Part")
swave.Shape = "Ball"
swave.Size = Vector3.new(3,3,3)
swave.CanCollide = false
swave.Transparency = 0.7
swave.BrickColor = BrickColor.new("Medium blue")
swave.Material = "Neon"
swave.TopSurface = "Smooth"
swave.BottomSurface = "Smooth"
swave.Anchored = true
swave.CFrame = Player.Character.HumanoidRootPart.CFrame*CFrame.new(0, 2, 0)
swave.Parent = workspace

for i = 4, -1, 0 do
	swave.Size = Vector3.new(1,1,1)

end

wait(1)
swave:Destroy()

end)

4 comments

0

at line 33, make it: for i = 4, 0, -1 do

0

yeah, it works but how would i make the ball increase in size? in this situation i cant figure it out.

0

i suggest putting this script in server script service, because currently the client can access replicated storage and fire that event

0

its already inside the server script service

1 answer

oh it think i found the problem. what your doing is using the for loop to change the value of "swave" to (1,1,1) every time it loops, keeping it the same size. your also using the for loop wrong. (x,y,z) x is the value the loop starts from, this should in your case be 4, y is equal to the number the loop will end at, in your case the loop will end when it reaches -1. z is equal to the number it counts up or down by, in your case, this should be -1

for i = 4, 0, -1 do
	swave.Size = swave.Size + Vector3.new(1,1,1)
        wait(0.25)
end
wait(1)
swave:Destroy()

end)

This discussion is preserved as it was. New answers, comments, and votes are closed.