Help with my script

Okay, so I am trying to make a script where when you touch a brick it will spin you, I want to know if I am scripting it correct or what I need to do

local brick = script.Parent
local plr = game:GetService(“Players”)

brick.OnTouch:connect(function()
plr.LocalPlayer.Character.HumanoidRootPart.Orientation = Vector3.new(“0,90,0”)
end

3 Likes

The parameters to Vector3.new are the x, y, z components, not a string. So you want Vector3.new(0,90,0) instead of Vector3.new("0,90,0").
You can use the console output to see these errors and save you a lot of time debugging simple mistakes like these.

Also its not “OnTouched” it is .Touched
brick.Touched:Connect(function()
And you cannot do plr.LocalPlayer if it is not on the client side.

end is supposed to be end)

1 Like
local brick = script.Parent
brick.Touched:connect(function(s)
if (s.Parent:FindFirstChild("Humanoid")) then else return end
s.Parent.HumanoidRootPart.Orientation = s.Parent.HumanoidRootPart.Orientation+ Vector3.new(0,90,0)
end)



2 Likes

Okay @oxazolone @HabibiBean @sz_s thank you for your quick responses, I am going to take those into account and am testing oxazolone script right now.

1 Like

Also note that this will not spin the character but it will just change his direction and make him spaz out.

1 Like

Oh, how would I spin the character for x amount of time?

This seems to make the character go away from the brick, I don’t think I did the orientation thing right, would it be a while true do loop with it constantly changing the orientation by 1 every second?

Do you want them to spin forever, or just a few times?

Just for a few seconds (30 characters)

Not necessarily, if the player was looking straightforward. he would stay at the same orientation due to the camera.
Though you can try it:

local rotation = 90
for i = 1, rotation do
     wait(0.1)
     s.Parent.HumanoidRootPart.Orientation = s.Parent.HumanoidRootPart.Orientation+ Vector3.new(0,1,0)
end

I would use if statements with a number (For example):

local number = 0
--Your Humanoid comparasion
if number <= yournumber then
    number = number + 1
    --Then rotate your humanoid
else
    YourEvent:Disconnect() --learn in depth what events are to understand this
end

And pls, use the three ` symbols for inser your code

Okay thanks for that tip, I am relatively new to devforum, but the thing is I am not sure how to go about rotating the humanoid?

2 Likes

Have you tried to look if the others code examples works?

This is not a good way of looping through numbers. The statement runs once. It is much more efficient to use a for loop.

1 Like

Also you could use while true do and then break it whenever you wan’t :slight_smile:

local brick = script.Parent
local plr = game:GetService(“Players”)

brick.OnTouch:connect(function()
while true do
plr.LocalPlayer.Character.HumanoidRootPart.Orientation = Vector3.new(“0,90,0”)
wait(1)

break
end
1 Like

This would require a value with an if statement to check if the rotation reaches a certain amount. For loops are the quickest and easiest way to achieve this.

Yes, oxazolone’s code worked but it is not really what I am trying to accomplish, which is a smooth rotation of the character for a few seconds, and HabibiBean’s code straight up does nothing (no offense)

@ekuz0diaa I’m assuming this is a server script, in which case you cant use localPlayer to get the player. To the server there is no local player, just a bunch of random player s that are connected to it, so it has no idea which player you’re talking about.

Sorry for not giving instructions, but it does work.

local brick = script.Parent
brick.Touched:connect(function(s)
if (s.Parent:FindFirstChild("Humanoid")) then else return end
local rotation = 10
for i = 1, rotation do
     wait(0.1)
     s.Parent.HumanoidRootPart.Orientation = s.Parent.HumanoidRootPart.Orientation+ Vector3.new(0,1,0)
end
end)