Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago
Edited 5 years ago
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

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. xPolarium 1388 — 5y
0
yes it was superior ( 45 ) LinkeeReiss 10 — 5y
0
maybe on 6 line type if b.WalkSpeed >= 30 then HaveASip 494 — 5y

1 answer

Log in to vote
0
Answered by
green271 635 Moderation Voter
5 years ago

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)
Ad

Answer this question