Script Support Needed!

why does my script not work ? and how to detect if player is standing on a specific part material?
what i am trying to do in this script is if the player is standing on sand the ball can be put in the player’s hand but when the player clicks when the tool is enabled the ball doesn’t appear anywhere !
script:


sand = workspace.Sand
water = workspace.Water
plr = game.Players.PlayerAdded:Wait()
char = plr.CharacterAdded:Wait()
hum = char:WaitForChild("Humanoid")
tool = script.Parent
ball = game.ReplicatedStorage.Handle

tool.Activated:Connect(function()
	ball.Parent = tool
end)
1 Like

Your script may be getting stuck on the CharacterAdded event as the player character may already be spawned. If it is then the tool activated connection is never made.

Try the line bellow:

char = plr.Character or plr.CharacterAdded:Wait()

Also, try cloning the ball first and then parenting the clone to the tool.

so i delete the char variable and hum variable?

Sorry, I just edited my response try changing that line to this:

char = plr.Character or plr.CharacterAdded:Wait()

yep i just did but doesnt work i deleted the hum and char variables i want to detect what material is the player walking on and to make the sand ball go to player’s hand using a tool with using welds

Also try changing:

game.Players.PlayerAdded:Wait()

with:

game.Players.LocalPlayer

If you want to detect what material a player is walking on, you have several options. The recommended approaches for accurately detecting the material include using Region3, Raycasting, or Humanoid.FloorMaterial. Using .Touched is not generally recommended as best practice for detecting materials, especially custom ones, due to its limitations and potential for inaccurate results.

Using Humanoid.FloorMaterial

For ROBLOX’s predefined materials like Plastic, Sand, and Water, you can use the Humanoid.FloorMaterial property. This property returns the material of the floor the humanoid is standing on.

Here is how you can use Humanoid.FloorMaterial in your script:

game.Players.PlayerAdded:Connect(function(plr)
    plr.CharacterAdded:Connect(function(char)
        local hum = char:WaitForChild("Humanoid")
        local tool = script.Parent
        local ball = game.ReplicatedStorage.Handle

        tool.Activated:Connect(function()
            if hum.FloorMaterial == Enum.Material.Sand then
                ball.Parent = tool
            else
                print("You are not standing on sand.")
            end
        end)
    end)
end)

still nothing doesn’t work :frowning: but i want to detect what material is the player walking on and to make the sand ball go to player’s hand using a tool with using welds

no, doesn’t work

1111111111111111111111111

what type of script are you using? I always gotta ask lol

np for the questions i want to detect what material is the player walking on and to make the sand ball go to player’s hand using a tool with using welds

Ok but what type of script is it?

server script
111111111111111111111111111111111

.Activated only works with local scripts. So youll probably if you need to do something on the server use a remote event.

idk how to use removte events that’s the problem

What’s the output when you run this code?

local tool = script.Parent
local ball = game.ReplicatedStorage.Handle

tool.Activated:Connect(function()
    local character = tool.Parent
    local humanoid = character:FindFirstChildOfClass("Humanoid")
    
    if humanoid and humanoid.FloorMaterial == Enum.Material.Sand then
        ball.Parent = tool
        print("You are standing on sand.")
    else
        print("You are not standing on sand.")
    end
end)

Tool.Activated can run on server scripts, basic sword scripts use this.

nothing
111111111111111111111111111111111111111

doesn’t work too

111111111111111112131321321231

This should help you
https://tinyurl.com/2af5kxoq