Trying to give cash for the player when makes kills

Basicly I am trying to give cash when the player makes one kill.

this is the bullet script (this bullet is inside the ReplicatedStorage and when the gun fire the bullet gets cloned into the workspace and will deal with damage on the player)

script:

local bullet = script.Parent
local HitSound = script.Parent.HitShotSound
local plr = game.Players.LocalPlayer
local leaderstats = plr:WaitForChild("toolLeaderstats")
local credits = leaderstats:WaitForChild("Credits")

local function player_check(otherPart)
	local humanoid = otherPart.Parent:FindFirstChild("Humanoid")
	if humanoid and humanoid.Parent.Name ~= bullet.Attacker.Value then
		if otherPart.Name == "Head" then
			humanoid:TakeDamage(100)
			HitSound:Play()
			if humanoid.Health >= 0 then
				credits.Value = credits.Value + 10
				bullet:Destroy()
			else
				humanoid:TakeDamage(50)
				HitSound:Play()
				if humanoid.Health >= 0 then
					credits.Value = credits.Value + 10
					bullet:Destroy()
				end
			end
		end
	end
end


bullet.Touched:Connect(player_check)
game.Debris:AddItem(bullet, 10)

erros:

I tried to make something like tag the humanoid but I forget I cant do game.Players:GetPlayerFromCharacter(tool.Parent) bc the bullet is not one member of the tool.

1 Like

I think this topic can help you

1 Like

Is this a LocalScript or Server Script? LocalPlayer is only accessible in LocalScripts. If you try to get the LocalPlayer on a server script, it will just return as nil. Thats why its giving you that error

server script bc I cant make one local script for kill the player.(the gun have one script with one remoteEvent for fireServer() the bullet)

I saw it before it works for swords etc. But I cant use it bc I cant make game.Players:GetPlayerFromCharacter(tool.Parent) but I got that system too.

So its about a gun, rn im making a Criminal vs. swat fangame so we’re in the same problem, ill try to make that and ill tell you.

Wait, you have a different script that fires a remote event? Is it related to this topic (not about the gun, but about the bullet being touched)?
Sorry for the late reply

Its me again, i was thinking and you should create the creator objectvalue when the tool is activated and the mouse.target is a player, just if you want to make a pistol without bullet ofc.

guys sorry I forget I have one script for the bullet settings inside the SSS (when the RemoteEvent is fired this script clone the bullet change the speed etc…)

And I can make the creator value here with the player name. I guess this will work

I will edit this post when I see if this works

  1. Is it a server script? if it is then local plr = game.Players.LocalPlayer won’t work as it is only for local scripts.
  2. Are you sure “toolLeaderstats” exist? if you are sure then try debugging.

yes tooLeaderstats exist but the real problem is I cant change the creator value with the player name (and I am using one normal script inside the bullet and the bullet is inside the RS) I tried that way (I cant do game.Players:GetPlayerFromCharacter() on the bullet because doesnt gonna work)

is the bullet.Attacker an object value?

no is one stringValue and I am using that for dont damage the player

this is the script inside the SSS with the bullet settings.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage.ToolsEvent:WaitForChild("MLGShootEvent")

RemoteEvent.OnServerEvent:Connect(function(player, gunPos, gunOr, mosPos)
	
	local bullet = ReplicatedStorage.ToolsBullets.Bullet:Clone()
	bullet.Parent = game.Workspace
	bullet.Position = gunPos
	
	local distance = (mosPos - gunPos).magnitude
	local speed = 650
	bullet.CFrame = CFrame.new(gunPos, mosPos)
	bullet.Velocity = bullet.CFrame.lookVector * speed	
	local fly = Instance.new("BodyForce",bullet)
	fly.Force = Vector3.new(0, bullet:GetMass() * workspace.Gravity, 0)
	bullet.Orientation = gunOr + Vector3.new(0, -90, 0)	
	
	local attacker = Instance.new("StringValue")
	attacker.Name = "Attacker"
	attacker.Parent = bullet
	attacker.Value = player.Name
	
end)

I tried to add the creator value (ObjectValue) but I cant and I cant change the parent with the enemy humanoid here.

Maybe you could make an object value and name it “Player” with the value as the player on the server then do this on the bullet script:

local player =  bullet.Player.Value

and try if it works

thats for put in the SSS script?

also I need to change the Parent into the enemy humanoid.

you put it on the event listener, yes.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage.ToolsEvent:WaitForChild("MLGShootEvent")

RemoteEvent.OnServerEvent:Connect(function(player, gunPos, gunOr, mosPos)
	
	local bullet = ReplicatedStorage.ToolsBullets.Bullet:Clone()
	bullet.Parent = game.Workspace
	bullet.Position = gunPos
	
	local distance = (mosPos - gunPos).magnitude
	local speed = 650
	bullet.CFrame = CFrame.new(gunPos, mosPos)
	bullet.Velocity = bullet.CFrame.lookVector * speed	
	local fly = Instance.new("BodyForce",bullet)
	fly.Force = Vector3.new(0, bullet:GetMass() * workspace.Gravity, 0)
	bullet.Orientation = gunOr + Vector3.new(0, -90, 0)	
	
	local attacker = Instance.new("StringValue")
	attacker.Name = "Attacker"
	attacker.Parent = bullet
	attacker.Value = player.Name
	
	local tag = Instance.new("ObjectValue") -- I think I have to change here for one StringValue
	tag.Name = "creator"
	tag.Value = player.Name
	
end)

This is what I did but I cant change the parent here (I have to parent the value with the enemy humanoid.)

try this

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage.ToolsEvent:WaitForChild("MLGShootEvent")

RemoteEvent.OnServerEvent:Connect(function(player, gunPos, gunOr, mosPos)
	
	local bullet = ReplicatedStorage.ToolsBullets.Bullet:Clone()
	bullet.Parent = game.Workspace
	bullet.Position = gunPos
	
	local distance = (mosPos - gunPos).magnitude
	local speed = 650
	bullet.CFrame = CFrame.new(gunPos, mosPos)
	bullet.Velocity = bullet.CFrame.lookVector * speed	
	local fly = Instance.new("BodyForce",bullet)
	fly.Force = Vector3.new(0, bullet:GetMass() * workspace.Gravity, 0)
	bullet.Orientation = gunOr + Vector3.new(0, -90, 0)	
	
	local attacker = Instance.new("StringValue")
	attacker.Name = "Attacker"
	attacker.Parent = bullet
	attacker.Value = player.Name
	
	local tag = Instance.new("ObjectValue") -- dont need to change to string value
	tag.Name = "creator"
	tag.Value = player
end)

and how I will change the Parent Ik the creator value will be the player name (inside the bullet I cant use the touch event for change the Parent of the tag?)

why do you need to change the parent of the tag?