Questions about 4 things

This isnt really like the usual posts in scripting support. I dont know the difference between the 2 of these: If (code) do and If (code) then

I also dont really know the difference between (code):Connect and if (code) do. Any help is appreciated, thanks.

1 Like

isnt a thing there is if (code) then, do is for for (code) do.
basically if (code) then does a thing if the (code) is correct or not
for (code) do is in simple terms doing something for everything in that code

some examples:

-- if the player has less than 50 health heal him
local player = game:GetService("Players").Localplayer

if player.Character.Humanoid.Health <= 50 then -- <= 50 meaning 50 or lower
player.Character.Humanoid.Health = 100
end
-- kill all players
local players = game.Players:GetPlayers()

for i,v in pairs(players) do
v.Character.Health = 0
end

these are just basic examples though

for code():connect though it can be used for mutliple things mostly for functions though for example:

-- do something when a remoteevent is triggered
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function()
for i,v in pairs(game.Players:GetPlayers()) do
v.Character.Humanoid.Health = 0
end
end)
-- kills all players when remoteevent is triggered

hope this can help you

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.