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

Give More XP If Player is in Group? Give only certain amount if not in Group?

The title explains it all, but I accept any answer that can help meh. Thank youuuu

local debounce = false
local plr = game.Players.LocalPlayer

script.Parent.Touched:connect(function(hit)
	if hit.Name == "ABL_Ball" or hit.Parent:IsA("Tool") then
	    if not debounce then
		    debounce = true
		    local look = hit.Parent:FindFirstChild("BallHandler").Value
		        local found = game.Players:FindFirstChild(look)
		        local cash = found:FindFirstChild("leaderstats")
		        cash.XP.Value = cash.XP.Value + 5
		        print("Gave +1 SM")
		        wait(1)
		    debounce = false
	end
	elseif plr:IsInGroup(3164314) then --it might be best to use game.Players.PlayerAdded but idk how to gg
		if hit.Name == "ABL_Ball" or hit.Parent:IsA("Tool") then
			local look = hit.Parent:FindFirstChild("BallHandler").Value
	        local found = game.Players:FindFirstChild(look)
	        local cash = found:FindFirstChild("leaderstats")
	        cash.XP.Value = cash.XP.Value + 10
		end
	end
end)

Thanks,

LukeGabrieI aka EnergyBrickz

1 answer

✓ Accepted answer

I spent a bit of time assisting LukeGabriel with this code on codeshare. After enough editing we arrived at a solution to his problem. I have decided to put the code here to show the end product that worked.

Here is the server script, within specific parts in Workspace:

local debounce = false
local players = game:FindService("Players") 

script.Parent.Touched:connect(function(hit)
	if debounce then
		return
    end
    
    debounce = true
    
    if hit.Name == "Handle" and hit.Parent:IsA("Tool") then
      	local Ball = hit
        local BallHandlerVal = Ball.Parent:WaitForChild("BallHandler") 
      	local BallHandler = players:FindFirstChild(BallHandlerVal.Value) -- 
        local cash = BallHandler:FindFirstChild("leaderstats")
        if BallHandler and cash then 
            local EXPValue = cash:WaitForChild('XP')
            if BallHandler:IsInGroup(3164314) then
                EXPValue.Value = EXPValue.Value + 10 
                print("Gave +10 EXP")
            else
                EXPValue.Value = EXPValue.Value + 5 
                print("Gave +5 EXP")
            end
        end
    wait(1)
    debounce = false
    end
end)

Here is the LocalScript, within a StringValue, within the Tool:

local Tool = script.Parent.Parent
local StringVal = script.Parent

Tool.Equipped:connect(function(mouse)
	local player = game.Players.LocalPlayer
    StringVal.Value = player.Name
end)

I hope this was a good learning experience for you. Great job!

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