I Want a player to be able to touch part1 which would +1 to the intValueX then for them to go somewhere else. Then when they would touch Part2, IntValueZ would + however much IntValueX = to. Then IntValueX would = to 0. If That Makes Sense
All IntValues Are put in game.Players with the script below.
(IntValueZ Is The Same But In A Different Script)
I Really only know the basics of scripting and I was trying to make a part give you +1 Value to a intValue and it didn’t work out. I don’t know how to define where the intValue is and I Don’t Think I know how to add to the IntValue but I never got to that step.
This Is The script I Was Trying To Use. (Please Remember I’m Not The Best At Scripting)
I’ve Never Really understood FindFirstChild.
This Is My First Topic Please Be Nice And Thanks For The Help!
Using find first child accepts the name for an argument, not the class. If you want to use Find First Child, give the name of the player (NeoGaming_RBLX). If you want to get the general class of Player then use
game.Players:FindFirstChildOfClass("Player")
When adding them, you forgot an equals sign. There HAS to be an equal sign in the equation (unless the equation is an argument, like in a Vector3), and there’s a simple fix to this:
Doing this adds 1 to itself. It takes lesser time to write
4. I noticed that the word Humanoid isn’t in green like the word Player. You are using different quotation marks here. When writing a string, remember to start and end it with
this,
" --"Hello"
this,
' -- "Hi"
or this.
[[]] --[[This can be used to make
multiline strings or comments]]
Also, touching will fire multiple times so it’s safe to use a debounce. Here’s how it works:
local debounce = true
local part = script.Parent
part.Touched:Connect(function(hit)
if debounce then
debounce = false
if hit.Parent:FindFirstChild("Humanoid") then
game.Players:FindFirstChild("PlayerName").xValue.Value +=1
end
wait(2)
debounce = true
end
end)
you are trying to index with the string ‘Player’, when you should be indexing with the player name.
when changing the intValue, you need a full number. i.e Value = Value + 1 instead of Value + 1
try using
part.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
player.xValue = player.xValue + 1
end
end)
This is a better solution because the object that touched the part may be a sibling of a humanoid but not necessarily the character of a player, therefore you would get an error trying to find the player just off of the fact that a humanoid exists. @Bro_DsAFoot
Your code wouldn’t work. Try it out with 2 or 3 players. It’s only going to increment the stats of the first player it finds in game.Players, not the player who touched it.
Given the scenario, we can all infer that OP is trying to add it to the player who touches the part.
If the game is single player, or in studio this would work. But for a production game it would never be used. That’s why I wouldn’t have even suggested to use :FindFirstChildOfClass(“Player”) You’re never going to use that in a multiplayer game because it won’t return the player (which is the result he’s expecting.)
The alternative for find first child that doesn’t need the class and just the name is WaitForChild. Basically it waits until the child is found. Example:
local humanoid = script.Parent:WaitForChild("Humanoid")
If you are not using find first child in this scenario this is the other option
Did you change the wait for child argument to the real player name? As I said, it needs the exact name. Player is a class name, and the player object when someone joins is automatically named to their username so change it to look something like this:
The code @JC_D3nt0n would work. Make a variable for the Player after grabbing them from the method of the Players service :GetPlayerFromCharacter(Model) returns either the player object, or nil if there is no player for that model.
Yes That Works If I Change It To My UserName. But It Doesn’t Work If Someone Else Touches The Part. So How Would I Change It To Something That Would Work For Anyones UserName?