Why is this print statement printing what's on my character?

I’m trying to get the serverscript to print which ore I’m touching, but instead of doing this, it decides to randomly print elements of my avatar for some odd reason. I’m unsure how to solve this, as I believe it should run but it doesn’t run as intended.

Localscript

local Rock = game.Workspace.Rock
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Hitbox = script.Parent:WaitForChild("Hitbox")
local replicatedStorage = game:GetService("ReplicatedStorage")
local OreTouchedEvent = replicatedStorage.OreTouchedEvent

Hitbox.Touched:Connect(function(player)
	OreTouchedEvent:FireServer(player, Rock)
end)

Serverscript

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local OreTouchedEvent = ReplicatedStorage.OreTouchedEvent

OreTouchedEvent.OnServerEvent:Connect(function(player, Ore)
	print(Ore)
end)

You don’t need to pass the player parameter from the client to the server. The remote event already has a player parameter on the server.

This is what it prints, as I forgot to include it.
image

So, like this?

Hitbox.Touched:Connect(function(player)
	OreTouchedEvent:FireServer(Rock)
end)
OreTouchedEvent.OnServerEvent:Connect(function(player, Ore)
	print(Ore)
end)

change this

Hitbox.Touched:Connect(function(player)
	OreTouchedEvent:FireServer(player, Rock)
end)

to this

Hitbox.Touched:Connect(function(hit)
if not Player.Character then return end
if hit:IsDescendantOf(Player.Character) then return end
	OreTouchedEvent:FireServer(Rock)
end)

Yeah, just like that. It should work now.

Thank you! It’s pretty crazy how one thing can completely make the script not work…

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.