Im trying to make a dragon game and i currently need help with a ImageButton. Upon joining, the player obtains a firedragon egg which is basically created via
Instance.new("ImageButton")
to the player's inventory GUI when pressing the "Claim!" Button.
Now the player i supposed to go to the hatching machine where he has to press on the ImageButton(The firedragon egg) and the dragon will hatch. However, the whole Joining-present event is inside a localscript, while the hatching event is inside a serverscript inside of the machine (inside a clickdetector). I know 2 solutions to this:
Create a RemoteEvent(FireServer). But i do not understand that whole thing at all.
Turn the joining-reward into a serverscript and get the player who clicked the textbutton. which i also have no idea how to do. Any help?
function parentPressed()
script.Parent.click.Value = true
local plr = game.Players.LocalPlayer
if plr.leaderstats.Food.Value == 0 then
plr.leaderstats.Food.Value = (plr.leaderstats.Food.Value + 100)
if plr.leaderstats.Gold.Value == 0 then
plr.leaderstats.Gold.Value = (plr.leaderstats.Gold.Value + 500)
--Give Dragon Egg
local fireegg = Instance.new("ImageButton")
fireegg.Parent = game.Players.LocalPlayer.PlayerGui.Inventory.Frame
fireegg.Name = "FireDragon"
fireegg.Size = UDim2.new(0,100 , 0,100)
fireegg.Position = UDim2.new(0.031,0 , 0.044,0)
fireegg.Image = "rbxgameasset://Images/dragonfireegg"
fireegg.BackgroundTransparency = 1
fireegg.ZIndex = 3
fireegg.Visible = true
local hatchwho = game.ReplicatedStorage.HatchWho:Clone()
hatchwho.Parent = fireegg
--Dragon Part End
script.Parent.Frame1.Position = script.Parent.Frame2.Position
script.Parent.Frame2.Visible = false
wait(0.2)
script.Parent.Frame1.Position = script.Parent.Frame3.Position
script.Parent.Frame2.Visible = true
wait(0.2)
script.Parent.Parent.Visible = false
wait(5)
script.Parent.click.Value = false
end
Rem:FireServer(parentPressed)
end
end
end
script.Parent.MouseButton1Down:connect(parentPressed)

1 comment
You need to put this script on a server sided script. Then connect it with a remoteEvent. Fire the remoteEvent from a localscript with localPlayer and script.Parent. Learn about RemoteEvents here https://developer.roblox.com/en-us/api-reference/class/RemoteEvent