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

Text button not working correctly. Help please?

Hello. I am making a overhead chat system. This is my current code:

messagesto = script.Parent.Parent
function onClicked(clicker)
	local box = game.ServerStorage.HeadMessage:Clone()
	box.Parent = clicker.Character.Head
	box.Text = messagesto.TextBox.Text
	box.Name = 'Newmessage'
	messagesto.BackgroundColor3 = Color3.new(90, 7, 255)
	wait(5)
	player.Character.Newmessage:Destroy()
end



script.Parent.MouseButton1Down:connect(onClicked)

When I click the text button, I get this error,

'Players.bluestreakejjp.PlayerGui.ScreenGui.Frame.Sad.Script:4: attempt to index local 'clicker' (a number value)'

Help please.

######Edited ~ Tab your code correctly!

1 answer

✓ Accepted answer

Edit: As someone said, this LocalScript has no access to the ServerStorage, so use RemoteEvents instead.

That's because the parameters of MouseButton1Down are the x and y position of the mouse, not the player who clicked it. Just use: game.Players.LocalPlayer, assuming this is in a LocalScript, as all scripts in GUIs should be LocalScripts because the player that clicks it will always be the player who has the Gui.

Make a RemoteEvent inside the ReplicatedStorage named "CreateMessage"

And put these scripts in your game:

Script

function onClicked(player,message)
	local box = game.ServerStorage.HeadMessage:Clone()
	box.Parent = player.Character.Head
	box.Text = message
	box.Name = 'Newmessage'
	messagesto.BackgroundColor3 = Color3.new(90, 7, 255)
	wait(5)
	player.Character.Newmessage:Destroy()
end

game:GetService("ReplicatedStorage"):WaitForChild("CreateMessage").OnServerEvent:Connect(onClicked)

LocalScript

messagesto = script.Parent.Parent
local player = game.Players.LocalPlayer
function onClicked()
	game:GetService("ReplicatedStorage"):WaitForChild("CreateMessage"):FireServer(messagesto.TextBox.Text)
end



script.Parent.MouseButton1Down:Connect(onClicked)

That's all. :)

Original answer: (Wouldn't work online)

messagesto = script.Parent.Parent
local player = game.Players.LocalPlayer
function onClicked()
	local box = game.ServerStorage.HeadMessage:Clone()
	box.Parent = player.Character.Head
	box.Text = messagesto.TextBox.Text
	box.Name = 'Newmessage'
	messagesto.BackgroundColor3 = Color3.new(90, 7, 255)
	wait(5)
	player.Character.Newmessage:Destroy()
end

script.Parent.MouseButton1Down:connect(onClicked)

2 comments

0

You are correct, but unfortunately client doesn't have access to ServerStorage mate. And connect is deprecated ;)

0

Well, I did fix his error, but I guess you're right. I used the code, and made a few changes to it, but I missed the fact that it wouldn't work online. I've edited it now, using RemoteEvents.

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