Script not working, no errors

This is a local script, inside a Dummy. What I am trying to achieve is if a player is near the Dummy, the Dummy will chat the following.

local plr = game:GetService("Players").LocalPlayer
local char = plr:WaitForChild("Character") or plr.CharacterAdded:Wait()
local Dummy = script.Parent.HumanoidRootPart
local closestDistance = 10
local chat = game:GetService("Chat")

while true do
	task.wait(1)
	local distance = (char.HumanoidRootPart.Position - Dummy.Position).magnitude
	if distance <= closestDistance then
		chat:Chat(Dummy.Head,"Welcome to Sabway!")
	end
end

Is this a server script?

game.Players.LocalPlayer isn’t defined if so.

and if it’s a local script then it won’t execute if placed inside the workspace container.

2 Likes

That kinda familliar to groovydominoes52 script where like if you type something the npc reply to you to

1 Like

Then, where should I put it? And, yes it is a local script.

Put it inside StarterCharacterScripts and reference the dummy via workspace.Dummy or whatever its path is.

1 Like

local is defined!

Summary

This text will be hidden

1 Like

Yes, game.Players.LocalPlayer is defined for local scripts.

Those local scripts need to be in specific locations for them to execute though.

2 Likes

Hmmm, try putting the chat colors and see if its still working

1 Like

https://developer.roblox.com/en-us/api-reference/function/Chat/Chat

The third argument is optional, it defaults to Enum.ChatColor.Blue.

3 Likes

I tried it, doesn’t work? Did you meant StarterPlayerScripts?

There is a warning shown in the output, Infinite yield possible on 'Players.Chrisxxxzz:WaitForChild("Character"

1 Like

plr.Character.

Character is a property of the player not a child.

1 Like
local chat = game:GetService("Chat")
local players = game:GetService("Players")
local player = players.LocalPlayer

local dummy = workspace:WaitForChild("Dummy")
local hrp = dummy:WaitForChild("HumanoidRootPart")
local head = dummy:WaitForChild("Head")

while true do
	task.wait(1)
	local distance = player:DistanceFromCharacter(hrp.Position)
	if distance <= 10 then
		chat:Chat(head, "Hello world!")
	end
end

This is working on my end w/ a test dummy.

1 Like


Aha! I got it seems to be the problem on your local script. Big problem:

So heres my script that I tried:

local plr = game:GetService("Players").LocalPlayer

local char = script.Parent

local Dummy = game.Workspace:WaitForChild("R15")

local closestDistance = 10

local chat = game:GetService("Chat")

while wait(1) do

local distance = (char.HumanoidRootPart.Position - Dummy.PrimaryPart.Position).magnitude

if distance <= closestDistance then

chat:Chat(Dummy.Head,"Welcome to Sabway!")

end

end
1 Like