Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Error with mouse, saying mouse.target is the player?

I am trying to make a pickaxe to break blocks but the code isnt working inside the ore is a int Value and both scripts are in the tool, same with the remote event Error:Health is not a valid member of Player "Players.cjkizzy286" Ps in the local script its saying that the target is the right thing but in the server script its saying its the player. Local script:

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
mouse.Button1Down:Connect(function()
	local target = mouse.Target
	local gems = game.Workspace["Ore Generator"].Gems
	local equipped = true
	local debounce = false
	local pickaxeDamage = 10
	local pickaxeSpeed = 0.75
	local ttm = gems.Parent.StoredGems:GetChildren()
	if equipped == true and target:IsA("UnionOperation") then
		for i,v in pairs(ttm) do
			if v == target then
				if debounce == false then
					debounce = true
					print(target)
					script.Parent.Health:FireServer(target)
					wait(pickaxeSpeed)
					debounce = false
				end
			end
		end
	end
end)

Server Script:

script.Parent.Health.OnServerEvent:Connect(function(target)
	print(target)
	target.Health = target.Health - 10
end)

1 answer

✓ Accepted answer

The first argument passed through a remote event is always the player, what your referring to is the player!

Try this:

script.Parent.Health.OnServerEvent:Connect(function(Player, Target)
    print(Target)
    Target.Health = Target.Health - 10
end)

Read more here!

This discussion is preserved as it was. New answers, comments, and votes are closed.