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

How do i make the server fire the function?

Asked by 5 years ago
Edited 5 years ago

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

1 answer

Log in to vote
0
Answered by
Amiaa16 3227 Moderation Voter Community Moderator
5 years ago

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.

0
what do u mean i should change? in my scripts Gameplayer365247v2 1055 — 5y
Ad

Answer this question