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

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

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

✓ Accepted answer

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.

2 comments

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!

0

It's good, let me know if you ever need help again!

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