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

Help trying to figure out how to affect humanoids in touch functions?

Asked by
Raeso 5
5 years ago

myPart = Instance.new("Part",workspace) myPart.CFrame = CFrame.new(10, 0, 10)

function onTouch(myPart) local Char = myPart.Parent local Human = Char:FindFirstChild("Humanoid") if Human then local plyr = game.Workspace.Name local explosion = Instance.new("Explosion") explosion.Position = myPart.Position game.Workspace.name.BrickColor = BrickColor.Red end

end

myPart.Touched:Connect(onTouch)

I was using this script to generate an explosion and paint the torso of whoever touched it red, but I don't know how to do that. No matter what I try I can't change the value of the humanoid that touched the brick, can I have some help?

1 answer

Log in to vote
0
Answered by 5 years ago

First of all, you should put your code in a code block. Next, I don't completely know if I understood what you were trying to do correctly, but if I did this is how you would do it.

local myPart = Instance.new("Part",workspace)  -- create part
myPart.CFrame = CFrame.new(10, 0, 10)

function onTouch(myPart) -- touch function
    local Human = myPart.Parent:FindFirstChild("Humanoid")
    if Human then -- if humanoid exists to check if it's a player (so no error occurs)
        local Char = myPart.Parent -- get character
        local explosion = Instance.new("Explosion",myPart) -- create explosion
        explosion.Position = myPart.Position
        local BodyColors = Char:WaitForChild("Body Colors") -- get character's body colors (necessary to change color of characer)
        BodyColors.TorsoColor3 = Color3.fromRGB(255,0,0) -- change color to red
    end 
end

myPart.Touched:Connect(onTouch) -- connect touch function to touched event

The explosion kills the character almost instantly when you touch the part so the red torso is hard to see but it does change.

0
Thanks, also sorry for the code block thing, never touched this site lol. What I originally intended was to practice with certain properties, and I wanted to be able to play with affecting a humanoid whenever they touched something, and your adjustments did answer my original question, thanks! Raeso 5 — 5y
0
It's good, let me know if you ever need help again! MythicalShade 420 — 5y
Ad

Answer this question