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

Why my touched part w'ont find the player walkspeed ?

script.Parent.Touched:Connect(function(hit)
    local b = hit.Parent:FindFirstChild("Humanoid")
    if b ~= nil then
	wait()
        print("True / Humanoid Hit")
		if b.WalkSpeed > 30 then
			wait()
			script.Parent.Anchored = false
			print("True / Destroyed Part")
		end
    end
end)

YES the walk speed was at superior of 30

When i touch the part the output say that ( True / Humanoid hit ) but it not showing the other print and it not unanchor the part

3 comments

0

Humanoid's have a default WalkSpeed of 16. Are you sure it's above 30 when you touch the part? Line 6 might not be meeting it's condition.

0

yes it was superior ( 45 )

0

maybe on 6 line type if b.WalkSpeed >= 30 then

1 answer

###WalkSpeed Replication

The WalkSpeed property of Humanoid is not replicated across the server and client. This means that the server will read the walkspeed as 16, unless it is set from the server.

We can use a RemoteFunction to get around this. Since RFs can return values, we will use it to return the player's walkspeed.

###Solution

-- place this in startergui (localscript)
-- create a remotefunction in replicatedstorage
-- name it "GetHealth"

local function health()
	return game.Players.LocalPlayer.Character.Humanoid.WalkSpeed
end

game.ReplicatedStorage.GetHealth.OnClientInvoke = health

Edited code:

script.Parent.Touched:Connect(function(hit)
    local b = hit.Parent:FindFirstChild("Humanoid")
    if b ~= nil then
    wait()
	local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
	local speed = game.ReplicatedStorage.GetHealth:InvokeClient(plr)
        print("True / Humanoid Hit")
        if speed > 30 then
            wait()
            script.Parent.Anchored = false
            print("True / Destroyed Part")
        end
    end
end)

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