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

How can i tell the humanoid floor??

i made this script it should work but it won't error or anything odd...

local mouse = game.Players.LocalPlayer:GetMouse()
local FloorMaterial = game.Players.LocalPlayer.Character.Humanoid

mouse.Button1Down:Connect(function()
	if FloorMaterial == Enum.Material.Grass then
			script.Parent.LocalScriptEnabler.Eat:FireServer()
	end
end)

1 answer

This isn't working because you haven't actually allocated the FloorMaterial property of Humanoid properly. The Conditional you've written actually check for the Humanoid, also attempts to compare it to an Enum type, which should definitely throw exceptions. Yet, I believe nothing is actually erroring because you're receiving something similar to an Infinite yield. This occurs when the attempted variable declaration is ran before the respective object has the time to load. We can actually condition the declaration to wait for said object before trying to allocate it!

All the code you're looking for will be below:

local Player = game:GetService("Players").LocalPlayer
local Cursor = Player:GetMouse()
local Character = Player.Character or Player.CharacterAdded:Wait()

Cursor.Button1Down:Connect(function())
	local Humanoid = Character:FindFirstChildWhichIsA("Humanoid")
	if (Humanoid) then
		if (Humanoid.FloorMaterial == Enum.FloorMaterial.Grass) then
			--// Remote Event Call
		end
	end
end)

2 comments

0

Please ensure this is a LocalScript within StarterPlayerScripts

0

Oh, it's in starter char scripts

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