#Is it possible to make it check if the player is in range twice when attacking?
120 messages · Page 1 of 1 (latest)
run the check twice
local function checkWithinRange()
local myPos, targetPos = Monster:GetCFrame().p, Monster:GetTargetCFrame().p
return (myPos-targetPos).Magnitude
end
if checkWithinRange() <= value then
...
if checkWithinRange() <= value then
...
end
end
something like that
a less clean way to do what you want to do would be running
if (Monster:GetCFrame().p - Monster:GetTargetCFrame().p) <= .... then ... end
twice
wtf?
this is not it
Does this replace the entire Attack() Function?
also what is the value here?
because it underlines red
It doesn't raplace the function, you can put the new function outaide Attack() or within it sepensing on if you want to get the same Magnitude value for other functions within the same script
Which one?
the <= value what does this refer to?
i dont know scripting that well
Would it look something like this?
just makes the player not take any damage at all this isn't it
You have to incorperate the conditional if checkWithinRange() <= value check into the Attack function
** You are now Level 12! **
also don't use local function like I showed in the example, use function since I didn't see it was a module script
<= - if value1 is less or equal to value2
>= if value1 is greater or equal to value2
function Monster:CheckWithinRange(Monster)
local myPos, targetPos = Monster:GetCFrame().p, Monster:GetTargetCFrame().p
return (myPos-targetPos).Magnitude --// gets the vector length between your position and the targets position
end
function Monster:Attack(Monster)
if self:CheckWithinRange(Monster) <= value then
...
if self:CheckWithinRange(Monster) <= value then
...
end
end
end
You might want to replace Monster:GetCFrame().p with a player element
since It's getting the CFrame of the object Monster twice instead of getting the CFrame of the Player and Monster
unless that's what you're intending to do
It is supposed to attack the player
So I'm assuming that means it needs to be a player element
I think this may work
It is damaging me only when I'm extremly close
Does this look right to you? Because it may be that I just have to adjust the attack ranges
Replace the Monster within tbe range function with NPC or something else since the module itaelf is called Monster already
Also you want to get the distance between the player and the monster, to di that you need to change the Monster witih the myPos variable with the Player
Which one of these do I change to monster?
I'm very confused I'm sorry I don't know what I'm doing
And by changing it to NPC do you mean Changing the Monster from Monster:CheckWithinRange cause im pretty sure that'll break the script as all other functions start with Monster:
The original used both as monster so I'm assuming I don't change it all?
I must've completely misunderstood you
to simplify your code a bit for your understanding
function Monster:CheckWithinRange(Monster)
local myPos = Monster:GetCFrame().p --// gets the Monsters CFrame
local targetPos = Monster:GetTargetCFrame().p --// Also gets the Monsters CFrame
return (myPos-targetPos).Magnitude --// gets the vector length between your position and the targets position
end
Within the module script, your module is called Monster
The only parameter you're currently passing through to the CheckWithinRange function is Monster
The names will conflict
The purpose of the CheckWithinRange function is to check the distance between the player and the monster if I'm correct
currently you're creating a local variable called myPos and another one called targetPos, but they're the same think
you're trying to take away the same value as the value from the value
e.g.
100(monster position) - 100(monster position)
this will equal to 0 and that's why you only get damaged when you're extremely close (when your range is less than 1)
you have to change one of the variables to take in the current players CFrame instead of the monsters
by adding a new parameter and changing the myPos variable you can get the result you want
function Monster:CheckWithinRange(Current_Player: Player,Monster)
local myPos = Current_Player:GetCFrame().p
....
end
I am assuming :GetTargetCFrame() is the same as :GetCFrame() since it's used for a NPC monster and no additional information is given to the function. This is the first time I've seen :GetTargetCFrame()
The script is not a module script btw
It's just a normal script
This is explained much better tho
I will have a look some time later
ah, woudln't recommend using : inbetween things then, since that's usually done within module scripts and confuses things a bit
oh
I was just wondering
if ur up to it
do u think it would be beneficial for me to send the entire script?
Just in case u do then here it is now cause I prolly won't be online when u are
This is what I have so far and it doesn't work
The monster runs towards where the player was standing when they first walked in range and then once the monster gets there it stops moving. It also never attacks
since it's not a module script replace the self:checkwithinrange with just CheckWithinRange(Monster)
also I'd recommend using local function instead of global function like you're using
@cedar osprey now what do I put instead of current_player
to get the player's CFrame
This changes nothing with how the script works
it's still broken
how do I fix it?
it was working before but the range was just too small
can you just tell me how to make it work with a large range
add print statements after each conditional check and check where the script stops working
or just skips
ok
This is the issue @cedar osprey
Line 323
It's cause the Current_Player doesn't exsist yet
It's hard to explain but I think I get it
Like here I changed it
It's getting the Player from the bracket's CFrame
But Player isn't anything
Like there's nothing telling what Player actually means
I think
U are the more knowledgable here
but there needs to be some way to actually detect the player who is being chased and make them the Player
Oh yeah
about that
they're different
I think that also has something to do with why it isn't working
GetTargetCFrame is getting the CFrame of the monster's target/player it's chasing
I'll show u
** You are now Level 11! **
but we've been misunderstanding the code this whole time
ignore what I said here
cause how u get the player's CFrame is with GetTargetCFrame
This is the new error I'm getting with my new code @cedar osprey
Ignore everything I said above here
The CheckWithinRange Works now just not a second time
im gonna try getting rid of Self:
Ok so that kinda worked
It's gone back to only attacking when you're extremly close to the monster now
I'd recommend looking at the code but I will show you the GetTargetCFrame part anyways
This is what GetTargetCFrame does
If I just edit the attack range value on the second CheckWithinRange then I can make it work
This is actually working pretty well
I think I'm happy with it
the :GetCFrame() function most likely takes in a Character input rather than a Player input that's why it error'd
if this works for you and you don't want to add much else to it then keep it as it is
Yeah
It took so long just to get here
So ye
I think I'll keep it
Thank for all your help though
not sure if you can help with this one as it's not as scripting-based
but I'm having a completely new issue with my monsters now
the last thing I want to add to them before they're complete is a death animation
this is the thread if ur interested #1162588409534091314 message
all good if ur not tho
like I said it's less scripting based and more animation based
and u've helped me a lot already
but maybe since you know a bit about the monster models already I thought I'd ask
unfortunately I haven't done anything much with animating as a whole so I won't be able to help you out with that