My script seems to work locally, but not on the server?

Basically, I have been working on a mining system, and I tried multiple fixes on the server script, but for some odd reason, the script will only work on a local script.

-- \\ Get-Services Variables // --

local RS = game:GetService("ReplicatedStorage")

local CS = game:GetService("CollectionService")

local SP = game:GetService("StarterPack")

-- \\ RS Variables // --

local Mine = script.Parent.Minin

-- \\ Tools // --

local HEAD = SP.Pickaxe["Meshes/Pick axe_Cube"]

-- \\ Functions // -- 


Mine.OnServerEvent:Connect(function()
	print("Well it fried")
	HEAD.Touched:Connect(function(Hit)
		print("Why would I hate?")
		print(Hit.Name)
	end)
end)


--[[if CS:HasTag(Hit, "Ores") then 
		print("Ores")
		local HP = Hit.Parent:GetAttribute("HP").Value
		print("StillWorking")
		print("Possibly still working")
		Hit.Parent:SetAttribute("HP", HP-1)
		print("Might be broken here")
		print(HP)
		if HP <= 0 then
			print("RockBroken")
		end
	else
		print("No tag, LOL")
	end]]

This is the server script, that can be moved to the local script, which worked.

-- \\ Player-Related Variables // --

local Player = game.Players.LocalPlayer

local Character = Player.Character or Player.CharacterAdded:Wait()

local HUM = Character:WaitForChild("Humanoid")

local DB = false


-- \\ Tool-Variable // --

local Tool = script.Parent

-- \\ Anim-Related Variables // --

local Idle = script.Parent.Idle

local IdleAnim = HUM.Animator:LoadAnimation(Idle)

local Mining = script.Parent.Mining

local MineAnim = HUM.Animator:LoadAnimation(Mining)
-- \\ Get-Service Variables // --

local RS = game:GetService("ReplicatedStorage")

-- \\ Event Variables // --

local Mine = script.Parent.Minin

local Head = script.Parent["Meshes/Pick axe_Cube"]

-- \\ Edits // --


Tool.Grip = CFrame.fromEulerAnglesXYZ(260, 55, 0)


--[[Tool.Equipped:Connect(function()
	
	IdleAnim:Play()
	IdleAnim.Looped = true
	
	
end)

Tool.Unequipped:Connect(function()
	
	IdleAnim:Stop()
	IdleAnim.Looped = false
	
end)]]

Tool.Activated:Connect(function()
	
	if DB == false then
		DB = true
		MineAnim:Play()
		Mine:FireServer()
		print("Can't relate tho")
		task.wait(2)
		DB = false
	end
	
	
end)

On the local script, I can post my server script under the fireserver part of the script, and it will work, printing out what I need it to print out.

Could it be that this part on the if statement it is looking to see if the “HEAD” is touched but the “HEAD” variable is linking towards something inside of the StarterPack and because it is inside of StarterPack it never touches something.

A fix to this I think could be done by doing something like below:

Mine.OnServerEvent:Connect(function(plr)
	local Pickaxe = plr.Character:FindFirstChild("Pickaxe")
	if Pickaxe then
		Pickaxe.Touched:Connect(function(Hit)
			print(Hit.Name)
		end)
	end
end)

So, this works. Although, the issue then becomes the part of the Pickaxe that needs to be register that it’s hitting something doesn’t work the way I’d like it to. It kind of just doesn’t work once I include the actual hitting part of the script.

What way do you want it to work then? I don’t really see any other way of doing it.

I fixed it, just had to redo your method once more on my actual pickaxe head part. Thank you so much.

1 Like