Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Kill = Levelup?

In there game there's a leaderstats and in intvalue called Level. This script is supposed to bring up the level by one on every ko the player gets. This script is located inside the tool (sword). It's supposed to award the player that kills the person with + 1 to the level.

--Define your player
local plr = game.Players.LocalPlayer

script.Parent.Handle.Touched:connect(function(hit)
    --Checks to make sure it's a player
    local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
    if plr then
        --Create the tag, place it in their Humanoid
        local tag = Instance.new('ObjectValue',hit.Parent.Humanoid)
        tag.Name = 'creator'
        -- value =  player instance
        tag.Value = plr
wait(.5)
local holder = script.Parent.Parent:GetPlayerFromCharacter()
local level = holder.leaderstats.Level
if tag.Parent.Health == 0 then
	level.Value = level.Value + 1
        --Tag Expire
        wait(.5)
        tag:Destroy()
		end
	end
end)

If it's possible that you explain/fix this that would be great thanks.

2 comments

0

Could you explain what doesn't work, and provide any errors?

0

The " :GetPlayerFromCharacter()" part doesn't seem to work which stops the leveling up. The tag part of the script works. Also when it is working it is possible that players farm for than one level up because they can smack the dead humanoid.

1 answer

✓ Accepted answer

:GetPlayerFromCharacter() is a member of game.Players, not the Model. The model would be the parameter.

--Define your player
local plr = game.Players.LocalPlayer

script.Parent.Handle.Touched:connect(function(hit)
    --Checks to make sure it's a player
    local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
    if plr then
        --Create the tag, place it in their Humanoid
        local tag = Instance.new('ObjectValue',hit.Parent.Humanoid)
        tag.Name = 'creator'
        -- value =  player instance
        tag.Value = plr
wait(.5)
local holder = game.Players:GetPlayerFromCharacter(script.Parent.Parent)
local level = holder.leaderstats.Level
if tag.Parent.Health == 0 then
    level.Value = level.Value + 1
        --Tag Expire
        wait(.5)
        tag:Destroy()
        end
    end
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.