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

How do you disable a script just for the player that activated it?

Asked by 3 years ago
Edited 3 years ago

So I added some money to my game but when a player touches it, it repeats the script and gives more money than it should. However, I created a code that makes the script only work once but when another player touches the money they don't get any.

I'm wondering if there's a way to disable the script locally and not get any extra money but for others to be able to get the money too.

Heres my code:

01WaitTime = 999999
02Amount = 25
03function onTouched(part)
04    local h = part.Parent:findFirstChild("Humanoid")
05    if (h~=nil) then
06        local thisplr = game.Players:FindFirstChild(h.Parent.Name)
07        if (thisplr~=nil) then
08            local stats = thisplr:findFirstChild("leaderstats")
09            if (stats~=nil) then
10                local Score = stats:findFirstChild("cash")
11                if (Score~=nil) then
12                    Score.Value = Score.Value + Amount
13                    end
14                end
15            end
16        end
17    end
18script.Parent.Touched:Connect(onTouched)

1 answer

Log in to vote
0
Answered by 3 years ago

Yeap there is a way in my case I used a table to insert their names when they get it and used a find function to see if they were in that table if not then it would give them money, otherwise it would print "ALREADYGOTIT".

01WaitTime = 999999
02Amount = 25
03 
04local alreadygotit = {}
05 
06function onTouched(part)
07    local h = part.Parent:findFirstChild("Humanoid")
08    if (h~=nil) then
09        local thisplr = game.Players:FindFirstChild(h.Parent.Name)
10        if (thisplr~=nil) then
11            local CHECKER = table.find(alreadygotit, thisplr.Name)
12 
13            if CHECKER == nil then
14            local stats = thisplr:findFirstChild("leaderstats")
15            if (stats~=nil) then
View all 28 lines...
0
Thank you so much! I wasted so much time trying to fix this and you helped me understand. delirik_1446 4 — 3y
Ad

Answer this question