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

Why isn't this rotating my model when remote-function is fired?

Why isn't this rotating my model?

There are no errors.

Please note: I have set the 'uis' and other shortened stuff to the corresponding things earlier in the script.

Here is the part of the very long local script that fires a remote functions when the R key is pressed:

uis.InputBegan:connect(function(inst)
	if Rotating == false then
		if placing == true then
		 if inst.KeyCode == Enum.KeyCode.R then
			local RotateEvent = game.Workspace.RemoteFunctions:FindFirstChild("RotateEventFor"..player.Name)
			RotateEvent:InvokeServer(id)
			Rotating = true
		 end
		Rotating = false
		end
	end
end)

Here is the part of the very long server side script that should start whenever the remote function is fired:

function event3.OnServerInvoke(id)
		
	local PartToRotate = game.Workspace:FindFirstChild("id",true).Value == id
	
	for i,v in pairs(game.Workspace:GetChildren()) do
		
		if v.Name == "ModelToPlaceFor"..plr.Name then
			
			if v:FindFirstChild("id").Value == id then
				
				PartToRotate = v.Parent
				
				PartToRotate:SetPrimaryPartCFrame(CFrame.new(PartToRotate.PrimaryPart.CFrame)*CFrame.Angles(0,0,math.rad(90 + PartToRotate.PrimaryPart.CFrame.Z)))
				
			end
			
		end
		
	end
	
end

As I previously stated;

There are 0 errors when I press the 'R' key in game, and I know that it connects correctly because I debugged it when the output said various stuff that I needed to fix.

Any help is greatly appreciated!

1 answer

✓ Accepted answer

The first parameter on OnServerEvent and OnServerInvoke are always the local player's object. (so do not make a remoteevent for each player)

so instead of function event3.OnServerInvoke(id) do function event3.OnServerInvoke(player, id)

1 comment

0

This was not exactly waht I was looking for, but it certainly helped me figure out the problem! Thank you.

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