#Score doubling when collecting

1 messages · Page 1 of 1 (latest)

amber marlin
#

I've been recently trying to get into scripting again, and for some reason whenever I touch a collectible, sometimes it multiplies the score it should give (50) by some integer. (Image and video related.) I think it has something to do with multiple limbs touching the part at the same tick.

icy storm
#

You need a debounce to prevent multiple limbs touching it

amber marlin
#

(btw the script's RunContext is set to Client)

icy storm
#
amber marlin
#

I tried it, and it's still counting multiple limbs.

lime hull
#

How does your score increase?

amber marlin
#

Basically I put an IntValue in the player (game.Players.examplePlayer) to keep track of score, and when a collectible is touched, it increases by the collectible's ScoreGive attribute, and then the collectible disappears.

lime hull
amber marlin
lime hull
#

Btw sorry if I take long to reply cuz this code is a bit hard to read

lime hull
#

Or did I miss it?

amber marlin
#

oh i thought you meant the one that handles actually getting the IntValue in there

#

mb

lime hull
#

no I mean like the script that does s.Value += part:GetAttribute("ScoreGive")or whatever

#

I looked back at the code and to be honest I don'T know. Though it is most likely that .Touched fires multiple times in one frame before debounce is set to false, so I'd probably do something like

-- more stuff up here
local debounce = true

c.Touched:Connect(function(p)
  if not debounce then return end
  debounce = false
  -- more stuff here
  if h and not debounce then
    -- stuff
  end
end)```

But it's fairly well known that `.Touched` is generally unreliable and it's not recommended to be used because there are better alternatives
atomic solarBOT
#

studio** You are now Level 1! **studio

molten zealot
unique shadow
#

Just cache the plr and if that plr has already got it then do nothing

lime hull
# amber marlin which ones?

There is GetTouchingParts() and spatial query functions like GetPartBoundsInBox() or GetPartBoundInRadius()

#

But they are less straightforward than .Touched but provide better reliability

#

Generally though, like I said, .Touched is unreliable but it is also vulnerable to exploiters / cheaters

amber marlin
hushed stream
lime hull
#

The spatial query functions from what I know are less performance heavy than GetTouchingParts(), so calling like 5 of them every frame shouldnt be extremely bad, but thats why people generally mix Raycast with these things to make sure they arent ran unnecessarily

#

But if OP can't find a solution, they should probably go back to .Touched then

amber marlin
#

I FOUND A SOLUTION!

I just changed the code to check if the part that's touching is the HumanoidRootPart, which is just one object, and (i think) less expensive on performance than the ones mentioned by softimpact.

hushed stream
unique shadow
#

Also I'm not sure but if this is only a one time pickup then u could do part.Touched:Once(function())

lime hull
#

I forgot :Once() exists LMAO

lime hull
amber marlin
atomic solarBOT
#

studio** You are now Level 3! **studio

amber marlin
#

great

hushed stream
unique shadow
hushed stream
#

like

#

detection

#

i wasnt talking about the connection

#

its the .Touched signal