Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would I make this mesh face the same direction as the player's character?

Asked by 5 years ago
Edited 5 years ago

So, I've been working at this for hours now, and I can't find anything in the forums. I want to make a spinning tornado mesh, and I need to make it face the same direction as the player, but I can't find a good way to do so. I had to use CFrame's in order to keep everything in place properly, and I'm really confused with it.

Script:

elseif key == Enum.KeyCode.T then

            local tpc1 = tornadoPunch:Clone()
            local tpc2 = tornadoPunch:Clone()
            local tpc3 = tornadoPunch:Clone()

            tpc1.Parent = game.Workspace
            tpc2.Parent = game.Workspace
            tpc3.Parent = game.Workspace

            tpc1.Orientation = rootPart.Orientation + Vector3.new(0,-90,0)
            tpc2.Orientation = rootPart.Orientation + Vector3.new(0,-90,0)
            tpc3.Orientation = rootPart.Orientation + Vector3.new(0,-90,0)

            tpc1.Position = rootPart.CFrame.p + rootPart.CFrame.lookVector*150
            tpc2.Position = rootPart.CFrame.p + rootPart.CFrame.lookVector*150
            tpc3.Position = rootPart.CFrame.p + rootPart.CFrame.lookVector*150

            setY(tpc1,rootPart)
            setY(tpc2,rootPart)
            setY(tpc3,rootPart)

            local db = false

            for i = 1,50,1 do

                tpc1.CFrame = CFrame.new(tpc1.CFrame.X,tpc1.CFrame.Y,tpc1.CFrame.Z) * CFrame.Angles(math.rad(i*8),0,0) -- This makes it spin, but I need the middle number to be whatever the middle number is for the character's HumanoidRootPart. How would I go about getting this number?
                tpc2.CFrame = CFrame.new(tpc2.CFrame.X,tpc2.CFrame.Y,tpc2.CFrame.Z) * CFrame.Angles(math.rad(i*12),0,0)
                tpc3.CFrame = CFrame.new(tpc3.CFrame.X,tpc3.CFrame.Y,tpc3.CFrame.Z) * CFrame.Angles(math.rad(i*16),0,0)

                tpc1.Size = tpc1.Size + Vector3.new(i/6,i/6,i/6)
                tpc1.Transparency = i/100 + 0.5

                tpc2.Size = tpc2.Size + Vector3.new(i/4,i/4,i/4)
                tpc2.Transparency = i/90 + 0.5

                tpc3.Size = tpc3.Size + Vector3.new(i/2,i/2,i/2)
                tpc3.Transparency = i/80 + 0.5
                wait(0.01)

                tpc2.Touched:Connect(function(hit)
                    local humanoid = hit.Parent.Humanoid
                    if humanoid ~= nil and hit.Parent.Name ~= player.Name and db == false then
                        humanoid:TakeDamage((powerLevel.Value*0.1)*math.random(5,15))
                        db = true
                        wait(5)
                        db = false
                    end
                end)
            end

            tpc1:Destroy()
            tpc2:Destroy()
            tpc3:Destroy()

        elseif key == Enum.KeyCode.V then

Any help would be GREATLY appreciated, thanks!

0
can you explain where this script is located? Also, why do you define a touch event within a for loop? SteamG00B 1633 — 5y
0
The touched event does damage, but that's not what I'm focusing on here. The script is in ServerScriptService, and there's a remote event firing it, but I asked for a way to get a certain part of an orientation of something. Knineteen19 307 — 5y
0
If the script is in ServerScriptService why is the server handling user input? User#24403 69 — 5y
0
The local script sends something telling the server script what key was pressed, but the key pressing goes down in the local script, not the server script. Knineteen19 307 — 5y
View all comments (21 more)
0
That's not the whole script, but you don't really need the whole script, because everything else is pretty much working just fine. Knineteen19 307 — 5y
0
Why is the server checking the key pressed? Your game will suffer from input lag for doing that. User#24403 69 — 5y
0
Well this script is for a sort of magic you could say. This magic has different moves, and I decided instead of doing a separate script for each move, I would just make one script that does all of the moves. Knineteen19 307 — 5y
0
I'm not referring to that at all. I'm asking why are you having the server check which key the player pressed. User#24403 69 — 5y
0
The local script checks what key the user presses, and if the user presses say r, it would play some animations for that move in the local script, then fire the server script. The server script would then check the key to know what move to do. Knineteen19 307 — 5y
0
Your game suffers from input lag then, and you should be playing animations client side. They will replicate. The server should never, under any circumstance, handle user input, either directly or indirectly. User#24403 69 — 5y
0
That wasn't the original question anyway. Knineteen19 307 — 5y
0
Animations are playing client side. And the key is just being sent to the server script as a variable that is checked. The server script isn't actually doing anything to the key, it's just reading what the key was. Knineteen19 307 — 5y
0
It's not at all "Handling" user input, it's just checking what the user input is . . . Knineteen19 307 — 5y
0
What he's trying to tell you is that your entire script needs to be fixed. It's simply in the wrong location, we are helping you by letting you know that it would cause so many problems in the long run to keep this where it is. Also if you move it, you may even realize how easy it is to solve your problem. SteamG00B 1633 — 5y
0
How many times do I have to say this . . . the problem I'm having has nothing to do with the location of the script. You say, "Your entire script needs to be fixed", yet how am I supposed to fix anything with vague answers like that? All I wanted to know was how I could make something face the same direction as my player, and be spinning while doing so. Knineteen19 307 — 5y
0
And why would I move a server script anywhere other than ServerScriptService, where server scripts are supposed to go. Incap never stated anything about the position of the script, he said I am having input lag issues, so where'd you get the idea my script location was the issue? Knineteen19 307 — 5y
0
We can't help you with that if the script is in the wrong location though. Which player is it supposed to be aligned with? If you just keep it where it should go, then you can just align it to the player that the script is in, otherwise, it's going to be more complicated than it needs to be. As for you saying it's not handling user input, if it checks any user input, then it is handling user input SteamG00B 1633 — 5y
0
Okay, I still don't get why you think the script location is the issue. I already said the script is in ServerScriptService, and it's being fired by a remote event from a client script in the player. That isn't the whole script, as I also already stated, so of course it's not just going to work like a charm. Knineteen19 307 — 5y
0
The script's not even in the player to begin with, that would work even less than it does now. Knineteen19 307 — 5y
0
make a module script holding everything you don't want to keep making a script for and then have a player script handling all the input. This whole script being in server scripts is the problem. If this script was inside the player, then you'd be able to orient it to the player however you wanted. SteamG00B 1633 — 5y
0
Even if your game only has 1 player max, there will still be lag SteamG00B 1633 — 5y
0
I already can orient it to the player however I want, that's kind of what remote events do . . . and I still need to learn how to use module scripts, because I have absolutely no idea how those work, if you have a good tutorial you would recommend, please send it. Knineteen19 307 — 5y
0
https://developer.roblox.com/api-reference/class/ModuleScript I don't have a tutorial because I went into this with prior knowledge, but I can explain it a bit. So you make a module script, and in it you make a bunch of functions (they can't be anonymous). In a separate script, at the top, you'd write "require(modulescript)" and then you can use the functions from the module script. SteamG00B 1633 — 5y
0
Mk. Knineteen19 307 — 5y
0
alright, I think I realized what you were doing wrong, you just asked the wrong question. What I think you meant was you needed either the X or Z lookVector of the character's humanoidrootpart. I fixed that in my answer, so if that fixes your problem, then go ahead and mark it as the accepted solution. SteamG00B 1633 — 5y

1 answer

Log in to vote
1
Answered by
SteamG00B 1633 Moderation Voter
5 years ago
Edited 5 years ago

Just focusing on this little section of your code here, assuming that you have moved it to starter scripts, where it should have been in the first place.

for i = 1,50 do -- you don't need to put increment by 1 because the default is 1

                tpc1.CFrame = CFrame.new(tpc1.CFrame.X,tpc1.CFrame.Y,tpc1.CFrame.Z) * CFrame.Angles(math.rad(i*8),0,script.Parent.HumanoidRootPart.CFrame.LookVector.Z) --this is where it was changed
                tpc2.CFrame = CFrame.new(tpc2.CFrame.X,tpc2.CFrame.Y,tpc2.CFrame.Z) * CFrame.Angles(math.rad(i*12),0,script.Parent.HumanoidRootPart.CFrame.LookVector.Z)
                tpc3.CFrame = CFrame.new(tpc3.CFrame.X,tpc3.CFrame.Y,tpc3.CFrame.Z) * CFrame.Angles(math.rad(i*16),0,script.Parent.HumanoidRootPart.CFrame.LookVector.Z)

                tpc1.Size = tpc1.Size + Vector3.new(i/6,i/6,i/6)
                tpc1.Transparency = i/100 + 0.5

                tpc2.Size = tpc2.Size + Vector3.new(i/4,i/4,i/4)
                tpc2.Transparency = i/90 + 0.5

                tpc3.Size = tpc3.Size + Vector3.new(i/2,i/2,i/2)
                tpc3.Transparency = i/80 + 0.5
                wait(0.01)

                tpc2.Touched:Connect(function(hit)
                    local humanoid = hit.Parent.Humanoid
                    if humanoid ~= nil and hit.Parent.Name ~= player.Name and db == false then
                        humanoid:TakeDamage((powerLevel.Value*0.1)*math.random(5,15))
                        db = true
                        wait(5)
                        db = false
                    end
                end)
            end

you could make a variable to handle the size of that line, but I put it all right there so it would be easier to understand what I did.

I have it set to X right now, but Z might also be what you were looking for. The Y look vector would always be 0 because that's the one aiming up into the sky, so it would stay the same unless your player was knocked down.

0
As I said, the script uses remote events, so I don't need to put the script in the player to make it work, and to access the player, but thanks, I'll try this! Knineteen19 307 — 5y
0
I might just be doing it wrong, but I don't think it's working. I did some testing with prints, and I found out that the Y value of the lookVector is always -0. This makes so the mesh is always in the same direction. Knineteen19 307 — 5y
0
I appreciate the attempt, but I don't think the lookVector of the HumanoidRootPart is going to solve my issue. My goal is to make the mesh align with the user's character. Here's what happens, even with your edits: https://gyazo.com/c77599900d12abeb7f1d277ec9ced59c. Knineteen19 307 — 5y
0
I think I might've had it in the wrong variable, it was hard for me to see with the editor on the website, I might've fixed it now. SteamG00B 1633 — 5y
Ad

Answer this question