Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Using UserInputService, but model is not rotating at all?

The script is supposed to rotate the model by 90 degrees, but it doesn't rotate all all. Here is the part of the script I think that is not working:

uis.InputBegan:connect(function(key)
	if key == Enum.KeyCode.R then
		model:SetPrimaryPartCFrame(model.HitBox.CFrame * CFrame.Angles(90, 0, 0))
	end
end)

Full script:

repeat wait() until game.Players.LocalPlayer and game.Players.LocalPlayer.Character
wait(0.01)
local modelname = script.Parent.Item.Value
local modeltype = script.Parent.ItemType.Value
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()

local model = game:GetService("ReplicatedStorage"):WaitForChild("Items"):FindFirstChild(modeltype):FindFirstChild(modelname):Clone()
local rserv = game:GetService("RunService")
model.Parent = workspace.CurrentCamera

local uis = game:GetService("UserInputService")

mouse.TargetFilter = model
function roundAToB(a,b)
	return(math.floor((a/b)+0.5)*b)
end
local sb = Instance.new("SelectionBox", model.HitBox)
sb.Color3 = Color3.new(100/255, 177/255, 105/255)
sb.Adornee = model.HitBox
mouse.Move:connect(function()
	local hit = mouse.Hit.p
	model:SetPrimaryPartCFrame(CFrame.new(roundAToB(hit.X,1),4,roundAToB(hit.Z,1)))
	--model:MoveTo(Vector3.new(roundAToB(hit.X,1),3.5,roundAToB(hit.Z,1)))
	--model:SetPrimaryPartCFrame(CFrame.new(model.HitBox.Position.X, 4, model.HitBox.Position.Z))
	local hb = model.HitBox
	wait()
	local region3 = Region3.new(
		Vector3.new(
			hb.Position.X-2,
			hb.Position.Y-3.5,
			hb.Position.Z-2.5
			),
		Vector3.new(
			hb.Position.X+2,
			hb.Position.Y+3.5,
			hb.Position.Z+2.5
			)
	)
	local partsinRegion = workspace:FindPartsInRegion3(region3, model)
	
	if partsinRegion[1] == nil then
		model.HitBox.SelectionBox.Color3 = Color3.new(100/255, 177/255, 105/255)
	else
		model.HitBox.SelectionBox.Color3 = Color3.new(162/255, 59/255, 52/255)
	end
	
end)

uis.InputBegan:connect(function(key)
	if key == Enum.KeyCode.R then
		model:SetPrimaryPartCFrame(model.HitBox.CFrame * CFrame.Angles(90, 0, 0))
	end
end)

mouse.Button1Down:connect(function()
	if model.HitBox.SelectionBox.Color3 == Color3.new(100/255, 177/255, 105/255) then
		local new =model:clone()
		new.Parent =model.Parent
		new.HitBox:Destroy()
		model.HitBox.SelectionBox.Color3 = Color3.new(162/255, 59/255, 52/255)
		new.Name = "Placed"..model.Name
		new.Parent = workspace
	else
	end
end)

GAME IS NOT FILTERINGENABLED | THIS IS A LOCALSCRIPT also everything else works

1 answer

✓ Accepted answer

#What your problem is You forgot to check the key's KeyCode!


#Final Product

uis.InputBegan:connect(function(key)
    if key.KeyCode == Enum.KeyCode.R then
        model:SetPrimaryPartCFrame(model.HitBox.CFrame * CFrame.Angles(90, 0, 0))
    end
end)

Hope it helps!

1 comment

0

hanks again :)

This discussion is preserved as it was. New answers, comments, and votes are closed.