When I fire my event (On my server script) it give me the error: player argument must be a player object. What the heck is wrong?
script:
local Water = script.Parent.Union
local Rep = game:GetService("ReplicatedStorage")
local WaterDrank = Rep.WaterDrank
local Players = game.Players
local DB = false
local WaterTool = script.Parent.Parent
WaterTool.Activated:Connect(function(player)
if not DB then
print("work")
DB = true
WaterDrank:FireClient(player)
wait(1)
DB = false
end
end)
One suggestion to fixing the problem is changing the way you get your “player” variable.
Instead of getting it from the parameter of the Activated event which seems to return nil, you can get the player simply by getting the parent of the tool (which is the player’s character) and then getting the player using the character.
local Water = script.Parent.Union
local Rep = game:GetService("ReplicatedStorage")
local WaterDrank = Rep.WaterDrank
local Players = game.Players
local DB = false
local WaterTool = script.Parent.Parent
--PlayerService
local playerService = game:GetService("Players")
WaterTool.Activated:Connect(function()
if not DB then
--player
local character = WaterTool.Parent
local player = playerService:GetPlayerFromCharacter(character)
print("work")
DB = true
WaterDrank:FireClient(player)
wait(1)
DB = false
end
end)