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?
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.