Code Not Running

Some of my code looks like it’s not running. It’s not giving any error messages, not doing its job incorrectly, it’s just like it’s commented out or something. All I get is a little flash of the preview model. I know that its code block is running because code right after it is running just fine.

Code: (Lines 15 and 16, Local script)

player = game.Players.LocalPlayer
mouse = player:GetMouse()
event = game.ReplicatedStorage.BuildEvent
tool = script.Parent
equipped = false
rotation = 0
ContextActionService = game:GetService("ContextActionService")

tool.Equipped:Connect(function()
    print("equipped")
    equipped = true
    Item = script.Campfire:Clone()
    Item.Parent = workspace
    mouse.TargetFilter = Item
    ContextActionService:BindAction("RotatePlus", function() Item:SetPrimaryPartCFrame(CFrame.Angles(0, math.rad(15), 0)) rotation = rotation + 15 end, true, Enum.KeyCode.Q)
    ContextActionService:BindAction("RotateMinus", function() Item:SetPrimaryPartCFrame(CFrame.Angles(0, math.rad(-15), 0)) rotation = rotation - 15 end, true, Enum.KeyCode.E)
    while equipped == true do wait(0.1)
        Item:SetPrimaryPartCFrame(CFrame.new(mouse.Hit.p))
    end
end)

tool.Unequipped:Connect(function()
    equipped = false
    ContextActionService:UnbindAction("RotatePlus")
    ContextActionService:UnbindAction("RotateMinus")
    Item:Destroy()
end)

tool.Activated:Connect(function()
    local pos = mouse.Hit.p
    print(pos, rotation)
    event:FireServer(pos, "Campfire", rotation)
    Item:Destroy()
    tool:Destroy()
end)

Is Item not being moved, or is it not being rotated? I’m assuming the second just because you specified the rotation bindings in your Equipped event, so I will probably answer that really quickly:

I think all you need to do is factor in the rotation created by rotation into your CFrame setting in line 18:

Item:SetPrimaryPartCFrame(Cframe.new(mouse.Hit.p) * CFrame.Angles(0,math.rad(rotation),0))

All you did was use the position, which means it ignores the rotation from rotation.

1 Like