Why is this simple script not working?

Hello! I want to create a script that will change the players walk speed when they hit it (For now it should just print something). It should be pretty simple and I have a very similar script that pops up a UI when a player touches it (Uses the same method I am trying with the new one I am trying to create).

The new one (when you touch it the players speed increases) is not working for some reason and it is copy and pasted from the working one just with a couple of changes so it does not pop up the UI when touched.

Please can anyone help me in why this is not working as I cannot find anything wrong with it. It is giving me no errors in the output.

(Sorry if it is a simple fix or error I am pretty new to scripting on roblox)

New Code (Not working):

local Players = game:GetService("Players")

local queueLine = false

local touchPart = script.Parent


touchPart.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local player = Players:GetPlayerFromCharacter(hit.Parent)
		if player then
			if queueLine == false then
				print("Player has entered the queue line!")
			end
		end
	end
end)

Old code (Working):

local TweenService = game:GetService("TweenService")
local Players = game:GetService("Players")

local debounce = false

local touchPart = game.Workspace.ApocTeleportPart

local apocTeleportNotification = script.Parent
local notificationSound = script.Parent.NotificationSound

local tweenEndPosition = UDim2.new(0.01, 0, 0.835, 0)
local tweenInfo = TweenInfo.new(
	0.5,
	Enum.EasingStyle.Sine,
	Enum.EasingDirection.Out
)
local notificationTweenON = TweenService:Create(apocTeleportNotification, tweenInfo, {Position = tweenEndPosition})


touchPart.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local player = Players:GetPlayerFromCharacter(hit.Parent)
		if player then
			if debounce == false then
				print("Player has stepped on teleport plate!")
				apocTeleportNotification.Visible = true
				notificationTweenON:Play()
				notificationSound:Play()
				debounce = true
				wait(5)
				debounce = false
				apocTeleportNotification.Visible = false
			end
		end
	end
end)

Cheers :slight_smile:

Unsure of what you did wrong, but my approach works.

Example

local Players = game:GetService("Players")

local touchPart = script.Parent
local walkSpeed = 50 -- change this to the desired walk speed
local queueLine = false;

touchPart.Touched:Connect(function(hit)
    local plr = Players:GetPlayerFromCharacter(hit.Parent);
    if (plr and not queueLine) then
        plr.Character:WaitForChild("Humanoid").WalkSpeed = walkSpeed
        print("Player's walk speed has been changed to "..walkSpeed)
    end
end)
1 Like

Hey thanks for getting back to me and helping me!

I tried your script and it worked fine! Not sure what it was but thank you :slight_smile:

Have a great rest of your day/night!

1 Like

Hey there!

No worries, you’re more than welcome. Best of luck with your goals.

Have a great one! :slight_smile:

1 Like

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