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

How to make this Master Script work?

Asked by 9 years ago

When a player touches temp his leaderboard will change to the value of temp, if a player touch tamp theirs will change to that value.

Why in one script? Less lag.

Temperature (Model) > MasterScript

TAMP (part) TEMP (part)

local ting = 0

function onTouched(hit)
    if ting == 0 then
    ting = 1
    check = hit.Parent:FindFirstChild("Humanoid")

    if check ~= nil then

        local user = game.Players:GetPlayerFromCharacter(hit.Parent)
        local stats = user:findFirstChild("leaderstats")

        if stats ~= nil then
            local cash = stats:findFirstChild("F")
                if cash.Value >= 0 then 
                cash.Value = cash.Value == 23
                end
            local cash = stats:findFirstChild("C")
                if cash.Value >= 0 then 
                cash.Value = cash.Value == ("-5")
                end
            script.Parent.TAMP.Touched:connect(onTouched)
        end

        if stats ~= nil then
            local cash = stats:findFirstChild("F")
                if cash.Value >= 0 then 
                cash.Value = cash.Value == 34
                end
            local cash = stats:findFirstChild("C")
                if cash.Value >= 0 then 
                cash.Value = cash.Value == 1
                end
            script.Parent.TEMP.Touched:connect(onTouched)
        end
    end
    ting = 0
    end
end
0
findFirstChild is deprecated, us FindFirstChild, and cash.Value = cash.Value + 23 TheDeadlyPanther 2460 — 9y

1 answer

Log in to vote
1
Answered by 9 years ago

These are all of your problems with this script:

1.

:findFirstChild() is deprecated, use :FindFirstChild()

2.

To change the value of a number:

local cash = script.CashValue

cash.Value = 1 -- changes the value
cash.Value = cash.Value + 1 -- adds 1 to the value
cash.Value = cash.Value - 1 -- takes away 1 from the value
cash.Value = cash.Value * 2 -- multiplies the value by 2
cash.Value = cash.Value / 2 -- divides the value by 2

3.

To make sure something is a player:

script.Parent.Touched:connect(function(hit)
    local p = game.Players:GetPlayerFromPlayer(hit.Parent) -- an npc can have a humanoid
    if p then
        -- code
    end
end)
Ad

Answer this question