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

Why doesn't the clickdetector on the shop npc work?

I have tried many things but none will work. Importing old scripts wont work either.

local shopguy = workspace.Map.Tom.ClickDetector


local NPCname = gui.NPCName.Text
local dialogue = gui.Dialogue.Text
local dialoguedb = false

Player = game:GetService("Players")["LocalPlayer"]
local playername = Player.Name
local char = Player.Character
local hum = char:WaitForChild("Humanoid")

shopguy.MouseClick:Connect(function()
	if not dialoguedb then
		dialoguedb = true
		gui.Enabled = true
		NPCname.Text = "Tom"
		local line1 = "Hey! Want to buy something from my shop? I've got all sorts of stuff!"
		
		local voice = game.Workspace.SoundLibrary.Voice:Clone()
		voice.Parent = shopguy.Parent.Head
		voice.SoundId = "rbxassetid://614988122"
		voice.PlaybackSpeed = 1.25
		for i = 1, #line1 do
			dialogue.Text = string.sub(line1, 1, i)
			wait(0.05)
			voice:Play()
		end
		wait(1)
		gui.Enabled = false
		dialoguedb = false
		voice:Destroy()
		local shopgui = script.Parent.ShopGUI
		shopgui.Enabled = true
	end
end)

It's a physical click that brings up a GUI and when the dialogue is finished it brings up another.

1 answer

I see a few things here that may be the problem, without the specific error message you get I won't be able to help much. However, I noticed that you attempted to get the Player from using ["LocalPlayer"]. That right there is most likely your problem. To get the player from LocalPlayer you need to use local scripts. In your case, you should get the player from the ClickDetector as there is a parameter in shop guy.MouseClick:Connect(function(), function that gives the player who clicked on the click detector.

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