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

Vector3 Issues, can I get help?

Pool = script.Parent

function onTouched(hit)

	local human = hit.Parent:findFirstChild("Humanoid")

	if (human ~= nil ) then 
		for i =0,1 do
			local Splash = Instance.new("Part")
			Splash.Parent = game.Workspace
			Splash.Position = human.LeftLeg.Position + Vector3.new(-1,-1,-1)
			Splash.TopSurface = "SmoothNoOutlines"
			Splash.BottomSurface = "SmoothNoOutlines"
			Splash.Transparency = .7
			Splash.CanCollide = false
			Splash.Shape = "Ball"
			Splash.formFactor = "Plate"
			Splash.Name = "Footprint"
			Splash.BrickColor = BrickColor.new("Really blue")
			Splash.Reflectance = 0
			Splash.Size = Vector3.new(1,.4,1)
			game:GetService("Debris"):AddItem(Splash, .5)
			
						
		end
	end
	
end


script.Parent.Touched:connect(onTouched)

This script is supposed to spawn a brick to the characters' LeftLeg ONLY. But no matter how much I toy with Vector3, it DOES (mostly) spawn at his left leg, but sometimes it'll also spawn right above the players' shoulders or head. How can I fix this?

Also, how would I go about making the brick spawn at the players' left and right leg? Would it be like this?

Splash.Position = human.LeftLeg and RightLeg.Position + Vector3.new(-1,-1,-1)

1 answer

✓ Accepted answer

The problem here was you were changing the Position of the part instead of the CFrame. Position has a specific behavior; if the new destination of the part is intercepting any other parts, then it teleports it upwards until it is no longer colliding with anything. To get around this problem you need to change the CFrame instead, which doesn't behave the way Position does.

To make the two splashes, you just need to clone a template twice and position the clones separately, since one part can't be located in two places at once.

Pool = script.Parent

local Splash = Instance.new("Part") --create a template for the splash object
Splash.TopSurface = "SmoothNoOutlines"
Splash.BottomSurface = "SmoothNoOutlines"
Splash.Transparency = .7
Splash.CanCollide = false
Splash.Shape = "Ball"
Splash.formFactor = "Plate"
Splash.Name = "Footprint"
Splash.BrickColor = BrickColor.new("Really blue")
Splash.Reflectance = 0
Splash.Size = Vector3.new(1,.4,1)

function onTouched(hit) --fire function when touched

    local human = hit.Parent:findFirstChild("Humanoid") --define humanoid

    if human then --if humanoid exists then fire code
	    local L = Splash:Clone()--clone splash
	    local R = Splash:Clone()--clone splash
	    L.CFrame = CFrame.new(human.LeftLeg.Position + Vector3.new(-1,-1,-1))--set position to left leg
	    R.CFrame = CFrame.new(human.RightLeg.Position + Vector3.new(-1,-1,-1))--set position to right leg
	    L.Parent = workspace--parent to workspace
	    R.Parent = workspace--parent to workspace
	    game:GetService("Debris"):AddItem(L, .5)--delete after .5 seconds
	    game:GetService("Debris"):AddItem(R, .5)--delete after .5 seconds
    end
end


script.Parent.Touched:connect(onTouched)

2 comments

0

Thanks dude!!

0

No Problem

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