Question About Script

So I was thinking of making an Arcade game. If the Instance.new() ball hits a part, you get +10 tickets to your leaderstats cash. Theres a String Value that stores the player’s name. I’m not sure how I’d add it to the player’s leaderstats if it does hit.

1 Like

local player

player.leaderstats.ValueName.Value+= 10

Example:

Part.Touched:Connect(function(ball)
   if ball.Name == "Ball" then
      player.leaderstats:WaitForChild("Tickets").Value += 1
end)

In a local script in the part its touching?

What do you mean? Are you trying to say if you should use a local script or a server script for the touched event?

Should this go into a local script?

Oh, no. This should be in a server script.

This is just an example. It’s not a full code

I don’t understand how it’d get the ‘player’ part. Thats what my main thread is asking.

Yup since the part could send multiple Touched events and add tons of cash to the leaderstat if he used that exact code

I understand its just a part of the code. I need to know how to add money to the user’s cash as the code above doesn’t seem it references a specific player.

You said you have a string value that stores the players name so do:

Part.Touched:Connect(function(ball)
    if ball.Name == "Ball" then
       local player = game:GetService("Players")[ball.StringValue.Value]
       player.leaderstats:WaitForChild("Tickets").Value += 10
    end
end)

Where is the StringValue that stores the player’s name located? Is it in StarterCharacterScripts, StarterPlayerScripts, ReplicatedStorage, etc.

local alreadytouched = {}
Part.Touched:Connect(function(ball)
	if ball.Name == "Ball" and not table.find(alreadytouched, ball) then
		table.insert(alreadytouched,ball)
		local player = game:GetService("Players")[ball.StringValue.Value]
		player.leaderstats:WaitForChild("Tickets").Value += 10
	end
end)