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

Awards crazy amouts of points?

So I have this "perfect" code:


--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 holderLevel = holder.leaderstats.Level
 if tag.Parent.Died:connect(script.Parent.Parent) then
    holderLevel.Value = holderLevel.Value + 1
        --Tag Expire
        wait(.5)
        tag:Destroy()
        end
end
end)

It works fine but the problem is it's awarding level + 1 whenever the person comes in contact with the object. Could you please help solve this? Thanks.

2 comments

0

Technically it is not perfect because their is a problem; but nothing is perfect.

0

Why do you have an event inside the if statement? That may be the reason.

1 answer

As you already said, the main problem is that the script always runs when the object is touched. You may stop this by adding a combinition of a boolean variable and an if statement. Like this:

Block = false 
if Block == false then
    Block = true
end

You can edit this as you like and use it to add delays, etc. too. Hope this helps and if you got any other question, feel free to ask.

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