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.