WiseMatheu
(WiseMatheu)
February 23, 2022, 10:23am
#1
Hey I’m wisematheu,
I’ve got this error that comes up when I click the button (please see images below) and it says ‘Unable to cast value to Object’ but I think the variables I put in the brackets do have values so I’m a bit confused.
Script inside a textbutton inside of a surfacegui in workspace
Local script inside starterplayerscripts under starterplayer
Code:
local event = game.ReplicatedStorage.MachineOrderEvents.Burger
local button = script.Parent
local orderNumber = game.ServerStorage.Ordernumber.Value
button.MouseButton1Up:Connect(function(player)
game.ServerStorage.Ordernumber.Value = game.ServerStorage.Ordernumber.Value + 1
event:FireClient(player,orderNumber)
print("Fired")
print(orderNumber)
end)
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local player = Players.LocalPlayer
local events = ReplicatedStorage:WaitForChild("MachineOrderEvents")
--Events--
burgerEvent = events.Burger
burgerEvent.OnClientEvent:Connect(function(orderNumber)
print("Printed!")
print(orderNumber)
return burgerEvent
end)
Mind sending a screenshot of what’s under ServerStorage
?
1 Like
Player is already automatically sent any value in the parameters is what’s next so the script thinks that the player is the ordernumber value
Just remove the player parameter
4 Likes
hi, can u show images of the hierarchy for the gui (and script)
2 Likes
Pretty sure this is correct solution.
1 Like
wait I’m confused, which line of code are u telling him to remove ‘player’ from
1 Like
WiseMatheu
(WiseMatheu)
February 23, 2022, 12:13pm
#8
I think line 7 and 5 of the server script (first image)
1 Like
Line seven in the server script
1 Like
But if he’s using FireClient, player is needed to define who is receiving the call
1 Like
Oopsies, true… so it’s not that. Hm.
1 Like
What type of value is Ordernumber?
Also assuming burgerEvent is a remoteevent,
you don’t need to return anything in the OnClientEvent
Also another word of disclaimer, you should put any interactable surfaceguis inside PlayerGui and adornee them to the part
2 Likes
I didnt think of that at all I don’t use fireclient often
2 Likes
Is the GUI a child of a part in the workspace? Please send a screenshot of its location.
2 Likes
It is, I believe he’s trying to use MouseButton1Up on the server, while he should be doing anything user input based on the client
2 Likes
WiseMatheu
(WiseMatheu)
February 23, 2022, 12:20pm
#16
The value of Ordernumber is an integar and I’ve now put the surfacegui inside the startgui
2 Likes
WiseMatheu
(WiseMatheu)
February 23, 2022, 12:21pm
#17
Hi, now it’s a child of startergui
2 Likes
Change it to a localscript now and you dont need to use a remoteevent at all
4 Likes
Great! That’s likely the issue. You cannot execute scripts in a GUI that is under a part of the workspace.
Edit: Nevermind, do what @InedibleGames is saying. Didn’t realise it was a Script
.
1 Like
WiseMatheu
(WiseMatheu)
February 23, 2022, 12:23pm
#20
I’ll test it when I’ve created a script in serverscriptservice brb
3 Likes