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

[SOLVED] Leaderstat value is not changing any help ?

I am making job for my game it is pizza delivery and i am making script to give money and score to player but when i try to change value nothing happend no errors or something it even print started so i want ask if somebody dont know what to do :c

workspace.Locations.GiveMoney.OnServerEvent:Connect(function()
	lplayer = script.Parent.Parent
	money = script.Parent.Parent.leaderstats.Money
	delivery = script.Parent.Parent.leaderstats.Deliveris
	okpizzajob = lplayer.Jobs.OKpizza
	
	if okpizzajob.Value == 1 then
		pizzatype = script.Parent.OKpizza.Job.Take.Pizza
		
		delivery.Value = delivery.Value + 1
		
		wait(0.1)
		if pizzatype.Value == 1 then
			money.Value = money.Value + 10
		end
		wait(0.1)
		if pizzatype.Value == 2 then
			money.Value = money.Value + 15
		end
		wait(0.1)
		if pizzatype.Value == 3 then
			money.Value = money.Value + 20
		end
	end
end)

1 comment

0

cant see an issue othere than that you should use "local" instead of just listing your variables.

4 answers

✓ Accepted answer

First, put your Remote Event in ReplicatedStorage (recommanded)

game.ReplicatedStorage.GiveMoney.OnServerEvent:Connect(function(player)
    local money = player.leaderstats.Money
    local delivery = player.leaderstats.Deliveris
    local okpizzajob = player.Jobs.OKpizza

    if okpizzajob.Value == 1 then
        local pizzatype = okpizzajob.Job.Take.Pizza

        delivery.Value = delivery.Value + 1

        wait(0.1)
        if pizzatype.Value == 1 then
            money.Value = money.Value + 10
        end
        wait(0.1)
        if pizzatype.Value == 2 then
            money.Value = money.Value + 15
        end
        wait(0.1)
        if pizzatype.Value == 3 then
            money.Value = money.Value + 20
        end
    end
end)

And put this script in ServerScriptService. Do double-check the variables and their location.

Please upvote and lemmeknow if it helps!

Edit: As discussed with you in Discord, the working script is:

game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function()
        money = player.leaderstats.Money
        delivery = player.leaderstats.Delivery
        gui = player.PlayerGui
        okpizzajob = player.Jobs.OKpizza

        game.ReplicatedStorage.GiveMoney.OnServerEvent:Connect(function()
            print(okpizzajob.Value)
            if okpizzajob.Value == 1 then
                pizzatype = gui.OKpizza.Job.Take.Pizza
                print(pizzatype.Value)

                if pizzatype.Value == 1 then
                    money.Value = money.Value + 10
                    print("Money Given")
                elseif pizzatype.Value == 2 then
                    money.Value = money.Value + 15
                    print("Money Given")
                elseif pizzatype.Value == 3 then
                    money.Value = money.Value + 20
                    print("Money Given")
                end
            else
                print("no job")
            end
        end)
    end)
end)

15 comments

0

still not working :c like script starts but it is not adding any money

0

Double check the variable that I assigned to pizzatype variable

0

Are you firing remove event from a local script?

0

yes

0

when i use this same thing but in local script it works but problem is i need it in script so other players can see leaderstats

0

I dont think it will work on Local script, as there is OnServerEvent, and did you keep the script in ServerScriptService?

0

And also check the local script that you are firing remote event of replicate storage only

0

everything is in good place and script is working i added print so i can see if it works and yes but it is not changing idk why and i have basicly same script in other game but there is localscript and it is working :/ idk why it have problem with server scrpt

0

it seems like int value cant be changed by server script :/

0

Try changing int value to number value

0

still not changing (like ofc i can change it to local script and then other player will not see others score)

0

Try removing wait()

0

still nothing :C

0

paste the script on dm on discord, Samyak@7649

0

ok my is MaximusMaaan#9963

try elseif

workspace.Locations.GiveMoney.OnServerEvent:Connect(function()
    lplayer = script.Parent.Parent
    money = script.Parent.Parent.leaderstats.Money
    delivery = script.Parent.Parent.leaderstats.Deliveris
    okpizzajob = lplayer.Jobs.OKpizza

    if okpizzajob.Value == 1 then
        pizzatype = script.Parent.OKpizza.Job.Take.Pizza

        delivery.Value = delivery.Value + 1

        wait(0.1)
        if pizzatype.Value == 1 then
            money.Value = money.Value + 10
        end
        wait(0.1)
        elseif pizzatype.Value == 2 then
            money.Value = money.Value + 15
        end
        wait(0.1)
        elseif pizzatype.Value == 3 then
            money.Value = money.Value + 20
        end
    end
end)

1 comment

0

nothing changed :(

If you are using it on a local script, you need to either A: Switch to a server script B: Make a remote event to change it on the server C: (NOT RECOMMENDED) Turn off filtering enabled on workspace properties

3 comments

0

nvm just realized you used ".OnServerEvent" so it's on a server (if it's on a local script then there is ur problem)

0

Turning off FE in the workspace won't actually turn it off. Where is that script/local script located?

0

sorry i was away and script is in PlayerGui

BTW it is server script and all values are in player and line line 8 is checker if player is in job or no

3 comments

0

May I know what actually Job is? Is it a stringValue?

0

IntValue 1 means that u are in job and 0 is that u are not in job. and job is just job :D like it is food delivery game

0

oh sowy job is folder where i will have other jobs i am stupid

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