|
Im making a Warrior cats game, in the book the cats starve if they don't eat, so im trying to make a script where every 5 seconds, the player takes a 5 damage
Local timewait = 5
function
wait(timewait)
While true do
game.workspace.players
damage.Players > 5
end
end
I really don't know if thats right, Please help me
Oh and before anyone says my script is horrible and stuff, iv'e tried learning to script, i study codes every day, its just VERY hard for me, so please, if your not going to help me out, don't post dumb little things like i suck at scripting, cause thats not useful |
|
|
|
And your script is completely messed up. |
|
aboy5643Join Date: 2010-10-08 Post Count: 5458 |
local timewait = 5 -- watch your caps on keywords like local
function name() -- You need to name functions and put "()" after them
wait(timewait) -- Good
while true do -- Capitalization on while
for i, v in pairs(game.Players:GetChildren()) do -- loop through every player
v.Character.Humanoid.Health = v.Character.Humanoid.Health - 5 --Make the humanoid lose 5 health
end -- end the for
end -- end the while
end -- end the function
name() -- call the function |
|
miz656Join Date: 2010-07-19 Post Count: 15336 |
What's your functions name and where are the parameters of it? |
|
|
I know my script is messed up, I just can't remember everything that comes in to scripting, and Lua is the easy one?! lol
Also that script, does it loop through every player then end, or does it damage them, wait so long, then keep damaging them? |
|
|
I think "While true do" should be "while true do" |
|
|
and miz, i really have no clue what you mean, sorry |
|
aboy5643Join Date: 2010-10-08 Post Count: 5458 |
My script damages EVERY player for 5 health every 5 seconds and will continue that forever. |
|
|
The ONLY thing i know in scripting is the wait, but i yet to learn where i can use that lol i have ideas for scripts, i just don't have the brain to make them work.... YET |
|
|
stravantForum ModeratorJoin Date: 2007-10-22 Post Count: 2893 |
"in the book the cats starve if they don't eat"
I think that that's more of a universal property of life that a property of the book =P
Anyways, the code you posted look like you just randomly wrote some bits you saw in other scripts down. Unfortunately scripting is like math, you have to be very precise for stuff to work, so you'll never get anything to work if you try to code it like that, you'll have to look up some explanations of how things generally work to have some starting point.
Heres a fixed version:
local WaitTime = 10 --5 is a bit short, don't you think?
local Damage = 5
while true do
wait(WaitTime)
for _, p in pairs(game.Players:GetChildren()) do
p.Character.Humanoid:TakeDamage(Damage)
end
end |
|
aboy5643Join Date: 2010-10-08 Post Count: 5458 |
For being able to admit that and know that, you will end up learning scripting with no problem. That's a lot of people's issue is that they get ahead of what their brain will let them do and get frustrated, ultimately ending up in failure. Realizing you can't do everything yet is a promising sign of a budding scripter. |
|
miz656Join Date: 2010-07-19 Post Count: 15336 |
Yeah, I would use stravant's code. It waits 10 seconds. It takes about 6 or 7 seconds for the player to respawn, making aboys script maybe to error. |
|
|
Lol yes i guess stravant, Ok, and yes and no, some stuff is i looked in others scripts, to see how its done, A lot of codes to me just looks like random stuff someone wrote, thats a reason why its hard.
Ill try both scripts, and tell you which is better, they both seem very good though
and yes 5 is a bit short i guess |
|
aboy5643Join Date: 2010-10-08 Post Count: 5458 |
@miz
That wouldn't affect anything. Stravant's and I's do the same thing. Only he removed the function() and left the index of the for loop anonymous which makes sense honestly :P and he tweaked the values to his liking lol. My code was perfectly valid and does the same thing. |
|
|
ABoys would be fine if you made sure that the character existed. The worry is more that if you don't eat in 20 seconds, you die. |
|
miz656Join Date: 2010-07-19 Post Count: 15336 |
There's really not a whole change except the waits and aboy subtraced while stravant used TakeDamage method. |
|
|
And ok, thank you for all the help
I really wanna learn how to write my own scripts, cause when im older i always wanted to design games, most times i try writing my own, HOPING to get a working one, so far though i haven't got a working one, but hey, i have plenty of time to learn, so one day ill learn how to script like pros lol but even the best need help once and a while. |
|
miz656Join Date: 2010-07-19 Post Count: 15336 |
"The worry is more that if you don't eat in 20 seconds, you die."
As of a fact you're dressed up like a chicken, maybe I should eat you...That'll give me 3 months worth of dinner ;D |
|
|
Lol thanks for all the help guys, i really couldn't have done it without help |
|
miz656Join Date: 2010-07-19 Post Count: 15336 |
You're kinda welcome. |
|
|
Ok the script works, but i did just found out why i made the time 5 lol unless i remove the helth regen, and idk how to do that nor do i think its possible, Well by the time the script goes back to 10, the player has full health again, so if i shorten the time, the script will be able to do damage faster then a player can gain health back, BUT im thinking, should i lower the damage and leave the time/make it higher, or should i lower the time? how would i do this |
|
|
Ok wait, i just thought of something thats very important, whats a players health? like before he takes ANY damage or anything, i heard its 100 |
|
aboy5643Join Date: 2010-10-08 Post Count: 5458 |
It is 100. Players regain health at 1 per second. Just take this into account with how much damage to give per second yourself. |
|