To avoid latency for moving parts, I’m trying to get a client sided kill brick working. I managed to get a client sided spinning-via-hinge brick working by putting in a local script that will load the part when the player joins the game, copying the model from replicated storage and putting it in the workspace. However, I noticed that the kill script does not work.
After looking for assistance, all I’ve gathered from other devforum posts is that I could use either a module script or remote event. I’ve never used module scripts before, and I hardly use remote events. I’d imagine I would need the kill part to launch an event to the server to kill the player. If I’m correct about that, how would I go about doing that? I’ve used client to server events before, but never in relation to a player interacting with a script inside a client sided part. Would I put a local script inside the part itself and have that connect to the remote event?
I’m just using this in StarterPlayerScripts to get the spinning part.
local LocalLaser = game.ReplicatedStorage:WaitForChild("SpinningLaser"):Clone()
LocalLaser.Parent = workspace
Try something like this, I haven’t tested it though
--client
local remoteEvent = -- location
local killpartFolder = -- location
local function onTouched(hit)
if hit.Parent:IsA("Player") then
remoteEvent:FireServer(hit.Parent)
end
end
for _,v in pairs(killpartFolder:GetChildren()) do
v.Touched:Connect(onTouched)
end
--server
local remoteEvent = -- location
remoteEvent.OnServerEvent:Connect(function(player, hit)
if player == hit then
local character = player.Character
local humanoid = character:FindFirstChild("Humanoid")
if humanoid then
humanoid.Health = 0
end
end
end
I tried this, doesn’t seem to do anything, and I am not getting any errors.
Where do I put the client sided script, and when defining where the lasers are, do I put the location it originally has in replicated storage, or its location in the workspace?