Simulator Sell Script is not Working

  1. What do you want to achieve? I am trying to make a sell script for my simulator.

  2. What is the issue? My script isn’t working even though it should.

  3. What solutions have you tried so far? Originally I made my own script and it didn’t work so I asked a friend about it and they couldn’t find anything wrong, but they gave me their script. I inserted it in, changed some things to fit with my game, and it still doesn’t work.

Script

local ifsound = false

script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
    
		if ifsound == false then
			
        	local Player = game.Players:GetPlayerFromCharacter(hit.Parent)

        if Player.leaderstats.Claps.Value >= 1 then
	
        	ifsound = true
			script.Audio:Play()
			
	        local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
	
		    Player.leaderstats.Money.Value = Player.leaderstats.Money.Value + Player.leaderstats.Claps.Value
		    Player.leaderstats.Claps.Value = 0
		
		    print("TEST")
		
	        wait(1)
	
	        script.Audio:Stop()
	
	        wait(0.5)
	
	        ifsound = false
	   end
    end
    end
end)

Thank you in advanced! -Blox :smiley:

Here is the explorer if needed, image

1 Like

Hey! Are there any errors in the output?

No I don’t think so. I will check again.

1 Like

It does not have any errors.

1 Like

Are the amount of claps the player has greater than 1? (ik its a silly question but just trying to figure it out lol)

Yes I have the clapping script made so I did it a few times before selling.

1 Like

What kind of script is the Clapping script? (localscript or regular script ?)

Server script. It is a child of the part.

can u show me in the explorer window?

I did! Scroll up lol!

No, not that script. You said you made a clapping script, that increases the number of claps right?

Oh ok! I will show you that.

Edit: I see the problem, it is a local script. Oops.

1 Like

alright my suspicions are true. By using a local script, you’re changing the stats of the player (number of claps) on the client (or the player’s computer basically), so the server doesn’t have access to that information. So to the server, your amount of claps is ALWAYS at 0. You need to use remote events to prevent this from happening. Its complicated, I’m sure you can find a video on it. (And no, just switching the script to a normal script will not work)

1 Like

Got it, thanks for making realize that. I will work on the remote event now!

1 Like

Np! If you’re satisfied, I would appreciate marking my reply as the correct answer.

1 Like