✓ 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
You are correct, but unfortunately client doesn't have access to ServerStorage mate. And
connectis deprecated ;)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.