Hello,
I am trying to send a Value with an Event from a LocalScript to a Script.and the problem is that it stops at Print(“Click”), it doesn’t want to get the Event.
If someone can help me it will be appreciated!
– Here is the LocalScript that I send from.
script.Parent.MouseButton1Click:Connect(function()
local player = game.Players.LocalPlayer
local shop = player.PlayerGui:WaitForChild("Shop")
local primaryMainFrame = shop:WaitForChild("PrimaryMainFrame")
local primarySafeArea = primaryMainFrame:WaitForChild("PrimarySafeArea")
local primaryItemInformation = primarySafeArea:WaitForChild("PrimaryItemInformation")
local primaryEquippedItem = primaryItemInformation:WaitForChild("PrimaryEquippedItem")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remotes = game.ReplicatedStorage:WaitForChild("Remotes")
local sendPrimaryItemInfo = remotes:WaitForChild("SendPrimaryItemInfo")
wait(.2)
sendPrimaryItemInfo:FireServer(primaryEquippedItem)
print("send")
– here is the Script that I get the Event.
open.MouseButton1Click:Connect(function()
print("Click")
local remotes = game.ReplicatedStorage:WaitForChild("Remotes")
local sendPrimaryItemInfo = remotes:WaitForChild("SendPrimaryItemInfo")
wait(.4)
local function onSendPrimaryItemInfo(PrimaryEquippedItem)
print("got it")
local primaryEquippedItem = PrimaryEquippedItem
for _, v in pairs(workspace.ToolModels:GetChildren()) do
if not v:IsA("Frame") then
v:Destroy()
end
end
local handle = game.StarterGui:WaitForChild("Folder"):FindFirstChild(primaryEquippedItem.Value.."Handle"):Clone()
handle.Parent = workspace.ToolModels
print("cloned")
handle.Script.Disabled = false
sendPrimaryItemInfo.OnServerEvent:Connect(onSendPrimaryItemInfo)
end
end)
https://streamable.com/wjc0ni
Your script is formatted weird but I believe its an issue with your function. (local function)
yes I know I am not good at organized, but what is the problem with the function?
If your doing remote events it should be remote.OnServerEvent:Connect(function(args)
I am also not sure what the point of the mousebuttonclick is in the server script
1 Like
its a long story,
because I need to clone a script and if I clone it with a LocalScript, the script will get broke something like that.so I need to clone it with a Script
Not sure why you are cloning the script but I dont see the point of firing a remote event if you already have mouseclick on the server script.
What instance type is primaryEquippedItem
?
I believe it’s because you are calling the Event to connect the function from within the function.
Try moving
sendPrimaryItemInfo.OnServerEvent:Connect(onSendPrimaryItemInfo)
outside of the function.
I am not firing the Button, I am firing a Value that its into the LocalPlayer.PlayerGui
and I cant access the PlayerGui with a script
so I am getting the value with a LocalScript and send it to the Script
Then why in the server script do you have MouseClick?
Also it wont work because you are only looking for the remote event .4 seconds after it being fired even though it got fired .4 seconds earlier causing it to never register.
AND you need to do remote.OnServerEvent for remote events.(Which I clearly stated earlier and so did @starnova224
its a Value that I am need his value for the server script and this Value is into the LocalPlayer.PlayerGui
So why not do remote.OnServerEvent? (as I have stated before)
1 Like
So is it a numbervalue? stringvalue? what type
the primaryEquippedItem its a StringValue
Wait so let me check if I’m understanding this correctly
You are trying to send a value from the server to the client?
If so you need to use
sendPrimaryItemInfo:FireClient(PlayerObject, Value)
He is trying to send a string value from the client to the server
no I am trying to send from the Client to the Server
because the Value its into the PlayerGui
Once again let me state this because you do not do this. You need to use remote.OnServerEvent when handling remotes that is why your script is not registering aka printing the “got it” part.
2 Likes
That is exactly why. You are sending the server the INSTANCE, not the VALUE. Heres what your primaryEquippedItem variable should look like. See if that fixes it.
local primaryEquippedItem = primaryItemInformation:WaitForChild("PrimaryEquippedItem").Value -- You need to add ".Value"
2 Likes