Urgent gun system scripting question

making a gun system and getplayerfromcharacter returns nil and IDK what to do somebody please help ive highlighted it in the script

ball = script.Parent
damage = 10
local Players = game:GetService("Players")
debris = game:GetService("Debris")
debris:AddItem(ball, 2)

HitSound = Instance.new("Sound")
HitSound.Name = "HitSound"
HitSound.SoundId = "http://www.roblox.com/asset/?id=0"
HitSound.Pitch = .5
HitSound.Parent = ball




function onTouched(hit)
	local humanoid = hit.Parent:findFirstChild("Humanoid")
	connection:disconnect()
	local bf = ball:FindFirstChild("BulletFloat")
	if (bf ~= nil) then 
		bf:Remove() 
		--script.Parent.Color = Color3.new(1,1,1)
	end

	if humanoid ~= nil then
		tagHumanoid(humanoid)
		humanoid:TakeDamage(damage)
		if humanoid.Health == 0 then
			local playerinstance = workspace:FindFirstChild(script.User.Value)
			print(playerinstance)
--HEREEEEEEEEEEEE
			local player = Players:GetPlayerFromCharacter(playerinstance)
			--player.PlayerGui.ScreenGui.Frame.TextLabel.Text = (humanoid.Name)
			print(player)
			
		end
		script.Parent:Destroy()
	end

	HitSound:Play()


end

function tagHumanoid(humanoid)
	-- todo: make tag expire
	local tag = ball:findFirstChild("creator")
	if tag ~= nil then
		local new_tag = tag:clone()
		new_tag.Parent = humanoid
		debris:AddItem(new_tag, 1)
	end
end



connection = ball.Touched:connect(onTouched)



Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

1 Like

What does playerinstance print?

playerinstance prints my name CENABOOSS

Try printing a child of your character like it’s HumanoidRootPart

it prints , its an instance thatis MY CHARACTer

the script is messy but playerinstance is character ISNTACE and player is the player

1 Like

Do you have a model or something in the workspace with the exact same name as your username?

That might be causing it to return nil

1 Like

i think i do let me try and see

1 Like

BRo THANKS SO mUCH I COULDNT HAVE THOUH OF THAT UR A LFIEASAVER

1 Like

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