i just started attempting server remotes so idk whats wrong but what im trying to do is when i holddown t then the player i click on will die
server script:
local Plr = game:GetService("Players"):WaitForChild("world_kiIIer") local remote = game:GetService("ReplicatedStorage"):WaitForChild("killplayer") local Mouse = Plr:GetMouse() remote.OnServerEvent:connect(function(world_kiIIer) world_kiIIer:GetMouse().Button1Down:connect(function() if not game:GetService("UserInputService"):IsKeyDown(Enum.KeyCode.T) then return end if not Mouse.Target then return end Mouse.Target.Parent.Humanoid.Health = 0 end) end)
local script:
local repstore = game.ReplicatedStorage local remote = repstore:WaitForChild("killplayer") local player = game.Players:WaitForChild("world_kiIIer") remote:FireServer(player)
my error: ServerScriptService.Script:8: attempt to index a nil value
if someone knows what im doing wrong please tell me, this is my first attempt on a serverscriptservice script
Yea well, first of all, you cannot GetMouse()
on the server. You can only use it in a localscript on the LocalPlayer.
The same applies to UserInputService. You can't check if the key is down on the server, only in a localscript.
Instead, try firing the Mouse.Target
to the server from the localscript, and let the server handle the rest.