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

Mounted turret script is unresponsive?

Hi there, scripters!

I have a problem with my turret script, which is intended to point towards the seat occupant's mouse coordinates, but it isn't sending a remote function that requests the mouse coordinates from a local script. I've had tons of problems with remote functions/events that send signals to the client before. Any help is appreciated!

server sided script:

seat = script.Parent.Seat
turretbase = script.Parent.TurretBase


seat:GetPropertyChangedSignal("Occupant"):Connect(function()
	while seat.Occupant ~= nil do
		local direction =	script.Parent.GetMouse:InvokeClient(game.Players:FindFirstChild(seat.Occupant.Parent.Name),seat.Occupant)
		turretbase.CFrame = CFrame.new(turretbase.Position,direction)
		wait(0.1)
	end
end)

client sided script (local script)

mouse = game.Players.LocalPlayer:GetMouse()

function script.Parent.GetMouse.OnClientInvoke(player,occupant)
	return mouse.hit.p
end

1 comment

0

Please help if you can, I can't seem to fix it! I've tried parenting the local script to ReplicatedFirst, but that doesn't work!

1 answer

You need to set OnClientInvoke to a function - either one you pass in or an anonymous one like below. Change your local script to:

mouse = game.Players.LocalPlayer:GetMouse()

-- You're not using the occupant argument here, but I left it in to show that the player argument isn't passed from server to client - i.e. InvokeClient(player, arg1) only uses the player argument to know who to send it to - it doesn't pass it to the client, so the client only sees arg1
function script.Parent.GetMouse.OnClientInvoke = function(occupant)
    return mouse.hit.p
end

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