Problem With Part and WalkSpeed

  1. What do you want to achieve? If i Touched my part then,
    Am have WalkSpeed = 6
    But if I not Tounched the part Then
    WalkSpeed = 16

  2. What is the issue? Hare my Problem
    If i touhed the Part am have walkSpeed = 6
    BUT
    if i not tounhed the Part am have Still walkSpeed = 6
    Hare Video – > Hare Problem

Script

MyBadParts.Touched:Connect(function(hit)
		if hit.Parent:FindFirstChild("Humanoid") then
			hit.Parent.Humanoid.WalkSpeed = 6 
			Walk = true
			print("Wee")
			if hit.Parent:FindFirstChild("Humanoid") == nil then
			print("False")
			end
		end
	end)
  1. What solutions have you tried so far? I now Its Something With Functin Return But i dont no how no use it.

You’re halfway there. You have to connect to TouchEnded as well and set the speed back to 16.

script.Parent.Touched:Connect(function(hit)
	local humanoid = hit.Parent:FindFirstChild("Humanoid")
	if humanoid then
		humanoid.WalkSpeed = 6
	end
end)

script.Parent.TouchEnded:Connect(function(hit)
	local humanoid = hit.Parent:FindFirstChild("Humanoid")
	if humanoid then
		humanoid.WalkSpeed = 16
	end
end)

Note: You will also need to debounce these touch events, which you can read about here

2 Likes

Hey dude you missed to define the variable MyBadParts

try this:

local MyBadParts = script.Parent -- Replace this to your "MyBadParts" part

local function setWalkSpeed(player, speed)
    if player and player.Character and player.Character:FindFirstChild("Humanoid") then
        player.Character.Humanoid.WalkSpeed = speed
    end
end

local isTouching = false

MyBadParts.Touched:Connect(function(hit)
    local character = hit.Parent
    if character and character:FindFirstChild("Humanoid") then
        character.Humanoid.WalkSpeed = 6
        isTouching = true
    end
end)

MyBadParts.TouchEnded:Connect(function(hit)
    local character = hit.Parent
    if isTouching and character and character:FindFirstChild("Humanoid") then
        character.Humanoid.WalkSpeed = 16
        isTouching = false
    end
end)

i hope this helps!

1 Like

Thx for help @Tyler148 @iDevYoyo

1 Like

So i just Test Thx For Function I real do it now For My future
but isTounching We dont need hare.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.