Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

(Please just read) Collide only after end of contact?

Please read

So I have a game here you run around, placing bombs, and hoping someone will get blown up by them. The bombs (at least, the part that collides) are a 4.5 stud wide spheres anchored just above ground. When the bombs are placed, they snap to grid at 5 stud intervals, so if you place 2 beside each other, you will have a 1 stud space. My issue is that these bombs are placed in an enclosed space, less than 7 studs high. The main problem is that when a bomb is placed, the player is inside the bomb, therefore glitching him/her. This is not a problem when the person is standing near the edge of the bomb; they will just be pushed backwards. However, when the bomb is placed, and the player is right in the center, or is against a wall (a likely scenario), the player will get stuck, therefore making him/her lose the round. My idea was that if a player is inside a bomb, it will be detected by the distance from the center of the bomb to the player. I though that you could just make a script that can keep the bomb's CanCollide property to false, until the player is no longer in the bomb. However, this could make it possible for people to walk through bombs, especially if there is more than one player near the bomb. My second idea was to make a script that creates a CollisionGroup for the player and the bomb, and then delete is after the player has left the sphere. Now, I don't think this would work, because 1: I already have a script that disables player-to-player collisions by CollisionGroups, and an item (the player in this case) cannot be in more than one CollisionGroup. Perhaps this won't be such an issue, but 2: What if two players are "inside"? Well yeah I have this kind of problem, I'm not really expecting a full script, but ideas. Thanks.

2 answers

If you do it in a local script, it will only occur for the player. Something like this might work if it’s in a local script:

local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
char:WaitForChild("HumanoidRootPart")

workspace.ChildAdded:Connect(function(part)
	if part.Name == "Bomb" and part:IsA("BasePart") then
		local dist = (part.Position-char.HumanoidRootPart.Position).magnitude
		if dist <= 4 then
			part.CanCollide = false
		end

		part.TouchEnded:Connect(function(hit)
			if hit == char.HumanoidRootPart then
				part.CanCollide = true
			end
		end)
	end
end)

Not sure if this would update fast enough to work without glitching though.

4 comments

0

thx, this helps a lot. Ill accept your answer after I test it, if it works. But i see an error here: if a player touches a bomb when he/she is not inside, the .Touched will fire and make the bomb walk-through. Also, are you sure that the CanCollide will affect only one player if changed via a LocalScript? Have you tested it?

0

Oh, I see what you mean about the error, I've edited the script to try and fix that, but anything done through local scripts will definitely only affect that player if FilteringEnabled is on.

0

First of all, my game (will probably) have a lot of lag. However, people told me that since the main script is run on the client, the server doesn't have to handle EVERYTHING, so the lag shouldn't be so extreme. Next, I have no idea how to work with FE on. Then, if I enable FE, I have to completely rewrite all my LocalScripts, and my main script is a local one. So basically, my game does not have

0

scriptinghelpers.org/questions/51968/anything-helps

I would just wait until the Character planting the bomb is just out of the part's radial distance. Some pseudo-code:

function dist(partA, partB)
    return (partA.Position - partB.Position).magnitude
end

function plantBomb(...)
    local bomb = Instance.new("Part")
    bomb.CanCollide = false
    ...

    local clearRadius = (bomb.Size.X / 2) + 1
    spawn(function()
        -- characterExists is just used to ensure we don't error when trying
        --    to access the character if the player died. You can refactor it
        --    if you already have a system in place for that, or just delete
        --    it if you don't are about errors after planting the bomb
        local characterExists
        repeat
            characterExists = player.Character
                and player.Character.Parent ~= nil
            wait()
        until (not characterExists)
            or dist(player.Character.HumanoidRootPart, bomb) > clearRadius
        bomb.CanCollide = true
    end)
end

1 comment

0

well yeah, but then players would be able to "hold a bomb open" for other players, so lets say you place it, and then you stay in it radius and let our friend or someone pass through. Just saying. But thx a lot anyway maybe ill accept later

This discussion is preserved as it was. New answers, comments, and votes are closed.