Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Why does the player have to jump against buildings to deal damage?

Asked by 5 years ago
Edited 5 years ago

Right now, for some odd reason, my touch detector isn’t working right. I want to make a system so that any buildings within 15 - 10 studs away will have 10% of the morph's damage value taken off, 9 - 5 will have 50% of the morph's damage value taken off, and any buildings 4 - 0 studs will have the full amount taken off, every 0.5 seconds. Currently, you have to jump against the building to deal any damage. Which is a problem, considering I have a no jump script. Each building has an int value called health, and the morph on the player has a value called damage. Please help me implement such a system! Script:

game.Players.PlayerAdded:Connect(function(player)
    local debris = player:WaitForChild("leaderstats").Debris
    player.CharacterAdded:Connect(function(character)
        for __, Part in pairs(character:GetChildren()) do
            if Part:IsA("BasePart") then
                Part.Touched:Connect(function(hit)
                    if hit:FindFirstAncestor("Buildings") then
                        print(hit)
                        print(hit:FindFirstAncestor("Building"):FindFirstChild("Health").Value)
                        hit:FindFirstAncestor("Building"):FindFirstChild("Health").Value = hit:FindFirstAncestor("Building"):FindFirstChild("Health").Value - character:FindFirstChild("Morph").Damage.Value
                        if hit:FindFirstAncestor("Building"):FindFirstChild("Health").Value <= 0 then
                            hit:FindFirstAncestor("Building"):Destroy()
                            print("Building destroyed.")
                        end
                        player.leaderstats.Debris.Value = player.leaderstats.Debris.Value + math.random(10,15)
                    end
                end)
            end
        end
    end)
end)

Any way this is possible? I will be releasing an update for my game, and this is the last thing I need to finish.

0
Side note: I need this because I will be adding a no jump script! NickIsANuke 217 — 5y
0
You can try to put wait() at line 4.. or make the morph damage lower.. I don't know what your script saying :V sorry ;(  Xapelize 2658 — 5y
0
the formatting is burning my eyes EmbeddedHorror 299 — 5y
0
Yeah, SH formatting is not the best. NickIsANuke 217 — 5y
View all comments (2 more)
0
I think its possible... I'm looking over how at the moment... JasonTheOwner 391 — 5y
0
Thx! NickIsANuke 217 — 5y

1 answer

Log in to vote
-1
Answered by 5 years ago
Edited 5 years ago

Try this? Added Regional Support below to be put into a separate script and PLACE this script in a server script in ServerScriptService

game.Players.PlayerAdded:Connect(function(player)
    local debris = player:WaitForChild("leaderstats").Debris
    player.CharacterAdded:Connect(function(character)
    -- copy in this script (cloned) to the Head of the Chracter Model.

    local s = game.ServerStorage.RegionalDestroyScript:Clone()
    s.Parent = character.Head
    s.Disabled=false


        for __, Part in pairs(character:GetChildren()) do
            if Part:IsA("BasePart") then
                Part.Touched:Connect(function(hit)
                    if hit:FindFirstAncestor("Buildings") then
                        print(hit)
                        print(hit:FindFirstAncestor("Building"):FindFirstChild("Health").Value)
                        hit:FindFirstAncestor("Building"):FindFirstChild("Health").Value = hit:FindFirstAncestor("Building"):FindFirstChild("Health").Value - character:FindFirstChild("Morph").Damage.Value
                        if hit:FindFirstAncestor("Building"):FindFirstChild("Health").Value <= 0 then
                            hit:FindFirstAncestor("Building"):Destroy()
                            print("Building destroyed.")
                        end
                        player.leaderstats.Debris.Value = player.leaderstats.Debris.Value + math.random(10,15)
                    end
                     wait(5) -- you could try waiting here 5 seconds or so...  THIS WAS THE ADDITION TO TRY FIXING THIS
                end)
            end
        end
    end)
end)

OK Add this to fine-tune your building destruction.. Don't even need to touch the part - it just needs to be 5 studs away from the character model (in all directions) Put his in your ServerScriptStorage named as RegionalDestroyScript and set the properties of it as Disabled=True

local character = script.Parent
local player = game.Players:GetPlayerFromCharacter(character)
local hit_once_already=false
print("***** REGIONAL DESTROY SCRIPT LOADED")
while wait(.5) do 
        local campos=script.Parent.CFrame.p



            for _,hit in pairs(game.Workspace:FindPartsInRegion3(Region3.new(campos+Vector3.new(-5,-2,-5),campos+Vector3.new(5,4,5)))) do
                            --print(hit.Name)
                         if hit:FindFirstAncestor("Buildings") and hit_once_already==false then
                                hit_once_already = true

                                print(hit) -- this works IF the hit point is in a model named BUilding, and the buidins in a Model named Buildings...
                                if hit:FindFirstAncestor("Building") or hit.Parent.Name=="Building" then
                                        if hit:FindFirstAncestor("Building"):FindFirstChild("Health") then

                                                 print(hit:FindFirstAncestor("Building"):FindFirstChild("Health").Value)
                                                hit:FindFirstAncestor("Building"):FindFirstChild("Health").Value = hit:FindFirstAncestor("Building"):FindFirstChild("Health").Value - 5--character:FindFirstChild("Morph").Damage.Value
                                                if hit:FindFirstAncestor("Building"):FindFirstChild("Health").Value <= 0 then
                                                    hit:FindFirstAncestor("Building"):Destroy()
                                                    print("Building destroyed.")
                                                end
                                               wait(3)   
                                        else
                                            print("the health value is missing for the building - be sure to add tis...")

                                        end
                                else
                                        print("Part that was hit, must be inside a model named 'Building'... hit.Parent>Name is instead:"..hit.Parent.Name)   
                               end
                             hit_once_already = false
                        else
                            print("hit item not in a model taht is inside a Buildings model")
                        end -- end check on FindFirstAncestor Building


            end

end


0
Wait, o the character is the head? NickIsANuke 217 — 5y
0
I think this is very overcomplicated. NickIsANuke 217 — 5y
Ad

Answer this question