I’ve been stuck at this simple task for days: rotate the model, but it doesn’t for some reason, i’ve checked some answers in other questions, nothing worked, it’s a localscript inside the starter gui:
(it’s inside the Inventory frame btw, TextButton)
here is the code
local tower = nil
local isPlacing = false
local uis = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local deb = true
local del = 0.1
local curDec = nil
local currentPos = {["X"]= 0, ["Y"] = 0, ["Z"] = 0}
function sendRaycast(blacklist)
local raypar = RaycastParams.new()
raypar.FilterDescendantsInstances = blacklist
raypar.FilterType = Enum.RaycastFilterType.Blacklist
local Origin = mouse.UnitRay.Origin
local direction = mouse.UnitRay.Direction * 1000
local raycast = workspace:Raycast(Origin, direction, raypar)
return raycast
end
function initDecoy()
local dec = tower:Clone()
dec.PrimaryPart.BrickColor = BrickColor.new("Really red")
--local rc = sendRaycast({dec})
--if rc then
dec.Parent = workspace
print("Success!")
--dec:SetPrimaryPartCFrame(CFrame.new(rc.Position))
return dec
end
for i, v in pairs(script.Parent:GetChildren()) do
if v:IsA("TextButton") then
v.Activated:Connect(function()
tower = v.Tower.Value
curDec = initDecoy()
isPlacing = true
end)
end
end
game:GetService("RunService").RenderStepped:Connect(function()
if curDec == nil or isPlacing == false then return end
local rc = sendRaycast({curDec, player.Character, game.Players:GetChildren(), workspace.Enemies:GetChildren()})
if rc then
local size = curDec:GetExtentsSize()
local position = CFrame.new(rc.Position+Vector3.new(0,size.y/2, 0))
curDec:SetPrimaryPartCFrame(position)
currentPos.X = curDec.PrimaryPart.Position.X
currentPos.Y = curDec.PrimaryPart.Position.Y
currentPos.Z = curDec.PrimaryPart.Position.Z
end
end)
uis.InputBegan:Connect(function(x)
if curDec == nil or isPlacing == false then return end
if x.KeyCode == Enum.KeyCode.R then
--curDec.PrimaryPart.CFrame = curDec.PrimaryPart.CFrame * CFrame.Angles(0, math.pi/4, 0)
curDec:SetPrimaryPartCFrame(curDec.PrimaryPart.CFrame * CFrame.Angles(0, math.rad(90), 0))
end
if x.KeyCode == Enum.KeyCode.Q then
curDec:Destroy()
curDec = nil
tower = nil
isPlacing = false
end
if x.UserInputType == Enum.UserInputType.MouseButton1 then
if deb == true then
deb = false
local ray = sendRaycast({curDec, player.Character, game.Players:GetChildren(), workspace.Enemies:GetChildren()})
if ray then
local t2 = curDec:Clone()
t2.Name = "TestTower"
t2.Parent = game.Workspace
local calculatedPosition = CFrame.new(currentPos.X, currentPos.Y, currentPos.Z)
t2:SetPrimaryPartCFrame(calculatedPosition)
if uis:IsKeyDown(Enum.KeyCode.H) then
t2.PrimaryPart.BrickColor = BrickColor.new("Bright blue")
else
curDec:Destroy()
curDec = nil
tower = nil
t2.PrimaryPart.BrickColor = BrickColor.new("Bright blue")
isPlacing = false
end
end
task.wait(del)
deb = true
end
end
end)
specifically, on line 62 - 65
if x.KeyCode == Enum.KeyCode.R then
--curDec.PrimaryPart.CFrame = curDec.PrimaryPart.CFrame * CFrame.Angles(0, math.pi/4, 0)
curDec:SetPrimaryPartCFrame(curDec.PrimaryPart.CFrame * CFrame.Angles(0, math.rad(90), 0))
end
if you need more info, please ask in the comments.
Thanks.