Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Help w/ clickdetector?

Asked by
FiredDusk 1466 Moderation Voter
8 years ago

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

Log in to vote
1
Answered by 8 years ago
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.

Ad
Log in to vote
0
Answered by
Nidoxs 190
8 years ago
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!

0
It did not add a point. FiredDusk 1466 — 8y

Answer this question