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

How do I make a click script that increases stats?

Asked by 3 years ago

How do you do it? It looks like its good and it has no errors! Heres the code:

local ting = 0

local Part = script.Parent
function onClicked(click)
    if ting == 0 then 
        ting = 1
        local check = click.Parent:FindFirstChild("Humanoid")

        if check ~= nil then 

            local p = game.Players.LocalPlayer
            local sstats = game.Players.LocalPlayer.leaderstats

            if sstats ~= nil then 
                local cash = sstats:findFirstChild("Wins")
                cash.Value  = cash.Value  + 1
                p:ResetCharacter()
                wait(7)
            end 

        end 

        ting = 0
    end 

end 


Part.ClickDetector.MouseClick:Connect(onClicked)
0
You can't change those values on a localplayer you have to m ake a serverscript sayer80 457 — 3y
1
i did snowpototoy 37 — 3y

1 answer

Log in to vote
0
Answered by
sayer80 457 Moderation Voter
3 years ago
Edited 3 years ago

Your issue is

  1. there is no localplayer on a serverscript
  2. click is the player
  3. the check is unneccessary as a block cant click the part and it stops the script as player:FindFirstChild("Humanoid") returns nil bc it has to be .Character
  4. :ResetCharacter doesn't exist

here the fixed version:

local ting = 0

local Part = script.Parent
function onClicked(player)
    if ting == 0 then 
        if not player then return end
        ting = 1

        local sstats = player:FindFirstChild("leaderstats")

        if sstats ~= nil then 
            local wins = sstats:FindFirstChild("Wins")
            local points = sstats:FindFirstChild("Points")
            if wins then
                wins.Value  += 1
            end
            if points then 
                points.Value += 5
            end
            player:LoadCharacter()
            wait(7)
        end 



        ting = 0
    end 

end 


Part.ClickDetector.MouseClick:Connect(onClicked)

Ad

Answer this question