Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Mounted turret script is unresponsive?

Asked by 6 years ago

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
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! SnazzySpider67 53 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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
Ad

Answer this question