Currently at work so I can’t paste the actual codes I’m using but they are very much based around this that was created via Google.
– Assuming the part is named “DamagePart”
local DamagePart = script.Parent
DamagePart.Touched:Connect(function(hit)
local humanoid = hit.Parent:FindFirstChild(“Humanoid”)
if humanoid then
humanoid:TakeDamage(10) – Change the damage value as needed
end
end)
I’m trying to make a Monkey Ball type game and I want there to be collision damage to the players when they hit each other but everything I try especially the portion above works only a few times then stops or doesn’t work at all and I can’t even get a print(“test”) in the output. I’m not asking for a whole script, my question is, how would I go about to make it so collisions deal damage? What am I missing?
The balls are spawned within the player so they have access to the humanoid for an ontouch function. O had it so the balls had an outter sphere named DmgBall so when they hit another named DmgBall they would give both players damage.
Another question would be if this script is player>Ball>DriverSeat>Script, how I would I call the humanoid without going script.parent.parent.parent.Humanoid?
I would recommend using Workspace ShapeCast or Workspace:Raycast(). In terms of performance, running a raycast does not have a strong performance impact compared to .touched().
To get the humanoid you could do [script instance]:FindFirstAncestor("Name of object containing humanoid").Humanoid
Do you know of any examples I can look into to learn about this? I’m still very much a newcomer to scripting lol. Farthest I have is understanding functions and yeah they do impact performance a bit.
I’ve seen raycast in the laser tag studio template but can’t make sense of it
I’ve experimented with them a tiny bit but im finding it difficult to put two and two together on the differences and benefits of the different scripting methods and etc… I’m still running on 2013 Lua
Tween I got down, I use that extensively especially for a lot of doors lol and animations lol. I’ve just scratched the surface with movements based on attachments. But yeah, functions, loops, tween is all I got lol I’ve never had a “need” to go this far into scripting but with the new games I’m trying to make, I’ve definitely fallen behind with it
The important question is, how large are the objects and how fast are they moving. Touched works well for detecting collisions of slower, larger objects. They are often misused as fighting game-style hitboxes, which is why you see people not reccomend you use them.
Atleast 12x12x12 balls. The gyro balls that are in the new studio tutorial. Speed wise, depends lol. They will be set at 200 (I think it was studs per something) but very fast lol
Lol it will be a Monkey Ball type demolition derby type thing. You can find it in my group WCRE WC Research and Exploration. The demo I made is Gyro Wars. Sorry for no link, just leaving work now!
I’ve tried looking into raycasts and the sphere cast, I just don’t think it would work in this game. Everything will be moving too fast at the players control and the reference pages for them suggest they quote singular direction. I could be wrong because I don’t know or understand it yet. However I am deciding the keep the touched() function but will approach it in a different way to maximize performance. I do thank all that comments with their thoughts and I will lol more further into the scripts to see what I can do.
This is what i’m doing for the damage, it’s not collision based in a sense of these 2 parts hit each other, but rather an outer part that can reach the player to cause damage. And yeah I have both a cooldown and check value to prevent it from killing instantly
teamColor = script.Parent.Parent.Parent.TeamColor
function onTouched(hit)
if hit.Parent:FindFirstChild("Humanoid") and game.Players:playerFromCharacter(hit.Parent).TeamColor~=teamColor.Value then
local debounce = false
local humanoid = hit.Parent:findFirstChild("Humanoid")
if humanoid and debounce==false then
debounce = true
humanoid.Health = humanoid.Health - 3
wait(.2)
debounce = false
end
end
end
script.Parent.Touched:connect(onTouched)