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

Help w/ clickdetector?

When I touch a part, it gives me 1 point then goes away and then comes back in 20 seconds. I want is when I click it. How would I do that?

amnt = 1
local PartClone=script.Parent:clone()
local CurrentParent=script.Parent.Parent

function onTouched(part)
    local h = part.Parent:findFirstChild("Humanoid")
    if (h~=nil) then
        local thisplr = game.Players:findFirstChild(h.Parent.Name)
        if (thisplr~=nil) then
            local stats = thisplr:findFirstChild("leaderstats")
            if (stats~=nil) then
                local score = stats:findFirstChild("Points")
                if (score~=nil) then
                    score.Value = score.Value + amnt
                    script.Parent:Destroy() --Added it in right here to destroy part
     wait(20)
     PartClone.Parent=CurrentParent
                end
            end
        end
    end
end

script.Parent.Touched:connect(onTouched)

I accept answers!

2 answers

✓ Accepted answer
amnt = 1
local PartClone=script.Parent:clone()
local CurrentParent=script.Parent.Parent

function onClicked(part) -- onClicked returns the player that clicked it, not a part. 
    local h = part.Character.Humanoid
    if (h~=nil) then
        local thisplr = game.Players:findFirstChild(h.Parent.Name)
        if (thisplr~=nil) then
            local stats = thisplr:findFirstChild("leaderstats")
            if (stats~=nil) then
                local score = stats:findFirstChild("Points")
                if (score~=nil) then
                    score.Value = score.Value + amnt
                    script.Parent:Destroy() --Added it in right here to destroy part
     wait(20)
     PartClone.Parent=CurrentParent
                end
            end
        end
    end
end

script.Parent.ClickDetector.MouseClick:connect(onClicked) -- Put a click detector inside script.Parent!

This is an edited version of doctorbenny's script. He forgot to account to the fact that clickdetectors return the player that clicked it and not a part.

amnt = 1
local PartClone=script.Parent:clone()
local CurrentParent=script.Parent.Parent

function onClicked(part)
    local h = part.Parent:findFirstChild("Humanoid")
    if (h~=nil) then
        local thisplr = game.Players:findFirstChild(h.Parent.Name)
        if (thisplr~=nil) then
            local stats = thisplr:findFirstChild("leaderstats")
            if (stats~=nil) then
                local score = stats:findFirstChild("Points")
                if (score~=nil) then
                    score.Value = score.Value + amnt
                    script.Parent:Destroy() --Added it in right here to destroy part
     wait(20)
     PartClone.Parent=CurrentParent
                end
            end
        end
    end
end

script.Parent.ClickDetector.MouseClick:connect(onClicked) -- Put a click detector inside script.Parent!

1 comment

0

It did not add a point.

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