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

Script doesn't work when i touch the button on touch?

Asked by 1 year ago
Edited by Shawnyg 1 year ago


function touched(hit) wait(.1) if hit.Parent~=nil then local h=hit.Parent:FindFirstChild("Humanoid") if h~=nil then if h.Health>0 then local s=hit.Parent:FindFirstChild("Shirt") local p=hit.Parent:FindFirstChild("Pants") local t=hit.Parent.Torso:FindFirstChild("roblox") if s~=nil then s:remove() end if p~=nil then p:remove() end h.MaxHealth=200 if t~=nil then if t.Texture=="http://www.roblox.com/asset/?id=3555194" then h.MaxHealth=500 <--------------------------i could cheat right here, but i like a fair game. :) else t:remove() end end h.Health=h.MaxHealth h.Health=h.Health-1 h.Parent.Head.BrickColor=BrickColor.new("Black") h.Parent:FindFirstChild("Torso").BrickColor=BrickColor.new("Light stone grey") h.Parent:FindFirstChild("Left Arm").BrickColor=BrickColor.new("Light stone grey") h.Parent:FindFirstChild("Left Leg").BrickColor=BrickColor.new("Light stone grey") h.Parent:FindFirstChild("Right Arm").BrickColor=BrickColor.new("Light stone grey") h.Parent:FindFirstChild("Right Leg").BrickColor=BrickColor.new("Light stone grey") end end wait(.5) end end script.Parent.Touched:connect(touched) --http://www.roblox.com/asset/?id=3555194
0
Place your code inside a code block, so it is easier to read.. xInfinityBear 1777 — 1y
0
Looks like you made the code block... Seems like you forgot to put the code in it. Put the code in-between the top and bottom lines when selecting the code block. xInfinityBear 1777 — 1y
0
I put it in a code block for you, but you have everything on one line... Shawnyg 4330 — 1y

1 answer

Log in to vote
0
Answered by 1 year ago

It should work, it's probably because half of your code is green (meaning it is included in the "--", usually it is used to put notes in the script and will not be run by the script).

function touched(hit)
    task.wait(0.1)
    if hit.Parent ~= nil then
        local h = hit.Parent:FindFirstChildWhichIsA("Humanoid")
        if h ~= nil then
            if h.Health > 0 then
                local s = hit.Parent:FindFirstChild("Shirt")
                local p = hit.Parent:FindFirstChild("Pants")
                local t = hit.Parent.Torso:FindFirstChild("roblox") 
                if s ~= nil then
                    s:remove()
                end
                if p ~= nil then
                    p:remove()
                end
                h.MaxHealth = 200
                if t ~= nil then
                    if t.Texture == "http://www.roblox.com/asset/?id=3555194" then
                        h.MaxHealth=500 --i could cheat right here, but i like a fair game. :)
                    else
                        t:remove()
                    end
                end
                h.Health = h.MaxHealth
                h.Health -= 1

                for _, limb in h.Parent:GetChildren() do
                    if limb:IsA("BasePart") then
                        if limb.Name == "Head" then
                            limb.BrickColor = BrickColor.new("Black")
                        else
                            limb.BrickColor = BrickColor.new("Light stone grey")
                        end
                    end
                end
            end
        end
        task.wait(0.5)
    end
end

script.Parent.Touched:Connect(touched)
Ad

Answer this question