How would i make this localscript into a normal script?

Alright so ive got this script here that basically does a bit of stuff, mainly do damage but the problem is that it only does damage in the client, how would i make it a serverside?

local tool = script.Parent
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
	tool.Touched:Connect(function(OtherPart)
	OtherPart.Parent:WaitForChild("Humanoid"):TakeDamage(10)
	script.Enabled = false
	wait(3)
	script.Enabled = true
	wait(3)
	script.Enabled = false
	if OtherPart.Parent:WaitForChild("Humanoid").Health == 0 then
		player.leaderstats.Gold.Value = player.leaderstats.Gold.Value + 50
		wait(0.4)
		script.Parent.Parent.Main.Enabled = true
		wait(1)
		script.Parent.Parent.Main.Enabled = false
	end
end)
2 Likes

Or add remote event that will remove hp from player or turn this script to server script

wait i realized most of the script works with the normal script. the only problem is this line:

player.leaderstats.Gold.Value = player.leaderstats.Gold.Value + 50

You could make it a remote but that will allow exploiters to grind gold very eazly.

yeah i know that remoteevents are dangerous for my game and stuff.

local tool = script.Parent
local da = true
tool.Touched:Connect(function(OtherPart)
	if OtherPart.Parent:FindFirstChild("Humanoid") and da == true then
		da = false
		local player = game.Players:GetPlayerFromCharacter(OtherPart.Parent)
		OtherPart.Parent.Humanoid:TakeDamage(10)
		wait(6)
		da = true
		if OtherPart.Parent:WaitForChild("Humanoid",5).Health == 0 then
			player.leaderstats.Gold.Value = player.leaderstats.Gold.Value + 50
			wait(0.4)
			script.Parent.Parent.Main.Enabled = true
			wait(1)
			script.Parent.Parent.Main.Enabled = false
		end
	end
end)

I dont think it will work first try.

the damage is still only on the clients screen :frowning:
obraz

i just realized its a server script not a local, sry lol.

Alright it works but theres a error " Players.MYNAME.Backpack.Baseball Bat.Kill part.LocalScript:11: attempt to index nil with ‘leaderstats’

you alredy show your name on imagine tho…

and it looks like somthing broke with leaderstats so there is no folder with this name or its named diffrent

local gold = Instance.new("IntValue")
	gold.Name = "gold"
	gold.Value = 0
	gold.Parent = leaderstats

this is my leaderstat

and heres yo script

player.leaderstats.gold.Value = player.leaderstats.gold.Value + 50

theres nothing wrong.

My gold is Gold but it should be gold so just hange it and should work

Should it be like this?

	local gold = Instance.new("IntValue")
	gold.Name = "Gold"
	gold.Value = 0
	gold.Parent = leaderstats
end

player.leaderstats.Gold.Value = player.leaderstats.Gold.Value + 50

well I would just hange gold in script but that will aslo work

so if i read right, and its a normal script, then the local player = game.Players.LocalPlayer wont work because it’s a normal script.

try this:

local mouse = player:GetMouse(player)
	tool.Touched:Connect(function(OtherPart)
	player.Character:WaitForChild("Humanoid"):TakeDamage(10)
	script.Enabled = false
	task.wait(3)
	script.Enabled = true
	task.wait(3)
	script.Enabled = false
	if player.Character:WaitForChild("Humanoid").Health == 0 then
		player.leaderstats.Gold.Value = player.leaderstats.Gold.Value + 50
		task.wait(0.4)
		script.Parent.Parent.Main.Enabled = true
		task.wait(1)
		script.Parent.Parent.Main.Enabled = false
	end
end)

You cant get player mouse from server script tho… (its not even used anywhere so next time check what are you coping)