Hey, so I want to send a BindableEvent to a script in the player, but it’s not working for some reason. Is there something else I can use to send information from a script in ServerScriptService to a script in the player? Both are regular scripts.
Basically what I’m doing is I’m cloning a script in ServerStorage using this script
local ClonedScript = game.ServerStorage:WaitForChild("ClonedScripts"):FindFirstChild("HatchingTimeScript"):Clone()
ClonedScript.Parent = eggValue--Parent the script to the egg folder
local HatchingTimeEvent = ClonedScript:FindFirstChild("HatchingTimeEvent")
HatchingTimeEvent:FireClient(plr)--Fire the bindable event so the script starts to work
Then parenting it to the player like this
Which works. Now all I need to do is get the script to run. I’ve tried both Bindable and RemoteEvents, but both of them don’t work unless I’m doing something wrong.
From server script to server script or local script to local script, you use bindables. Remotes is from local script to server script and vice versa.
If this script is a local script then it won’t run for several reasons.
Cloned scripts from the client won’t run unless it’s another local script
The client cannot access server storage
This situation would use remotes
The client would use RemoteEvent:FireServer because it’s sending the request to the server. This doesn’t require a player argument since roblox does some magic behind the scenes and automatically puts it first
-- server script (example)
RemoteEvent.OnServerEvent:Connect(plr, ...)-- the player who sent the request is auto passed as the first argument
-- do stuff
end)
-- local script (example)
RemoteEvent:FireServer(...)
Client and server is referring to scripts that you use, not objects. If an object is created on the server then both the client and server will see them, if an object is created on the client then only that client will see it
Client - Local Scripts and ModuleScripts that are called from local scripts. It’s also what you see on your screen and the roblox application that you use for your device but locally meaning only you would see them. If you want everyone to see something, use the server/remote events for it
Server - Server Scripts and ModuleScripts that are called from server scripts. It’s basically the server that’s running the game off of roblox’s servers
Sometimes things can be replicated between them, meaning, if the client does something then the server will see it too
So then I would use a Bindable if I’m cloning a script using a regular script and then parenting that cloned script to the player? Because when I do send the Bindable to the cloned script in the player doesn’t work, however if I parent that cloned script to something else such as the workspace it receives the Bindable.
Yes, you are correct. But to answer your issue, I believe this is due to the fact that server scripts can’t run under the Player Instance. Server Scripts and Local Scripts can only run while they’re parented to certain Instances (i.e. local scripts can’t run in workspace unless they’re a descendant of the player’s character). You would have to somehow reconfigure your system (if you have to) to have the script somewhere else, like in ServerScriptService but instead of cloning, just make a script that handles everything from it
Edit: sorry for long paragraphs, using mobile is a nightmare
Okay thank you. I was originally going to use one script in ServerScriptService that would loop through all of the players and decrease an IntValue like this
--loop through every player's hatching folder and have their egg hatch time go down
while true do
for i, player in pairs(game.Players:GetPlayers())do
local eggs = player.Backpack:FindFirstChild("Hatching")
if eggs:GetChildren() > 0 then
for i, egg in pairs(eggs:GetChildren())do
if egg.HatchingTime.Value > 0 then
egg.HatchingTime.Value = egg.HatchingTime.Value - 1
end
end
end
end
wait(1)
end
But if it took a while for the player to load in the other players would have to wait over a second for their IntValue to decrease. Is there a better solution that you know of, otherwise I guess I’ll just use this script for now since it somewhat works.
You could use the coroutine library so that other players don’t have to wait
while true do
for i, player in pairs(game.Players:GetPlayers())do
coroutine.wrap(function()
local eggs = player.Backpack:FindFirstChild("Hatching")
if eggs and eggs:GetChildren() > 0 then
for i, egg in pairs(eggs:GetChildren())do
if egg.HatchingTime.Value > 0 then
egg.HatchingTime.Value -= 1 -- better syntax, it's essentially the same thing but much shorter
end
end
end
end)()
end
wait(1)
end