Hello, I'm Fako16 and I'm a new scripter that's currently learning. I watched a AlvinBlox video that explained how FE click detectors work and I wanted to make a click detector that would give you resources like wood, stone, etc.. I started making it and it works fine in studio, but I remembered that if it works in studio, that doesn't mean it'll work in game and when I tested it in-game it didn't work. Can someone help me see why it doesn't work?
https://prnt.sc/jo6vc8 PLEASE CHECK THIS IMAGE BEFORE LOOKING AT SCRIPTS!
Script 1 -
game.Players.PlayerAdded:connect(function(player) local leaderstats = Instance.new("Folder", player) leaderstats.Name = "leaderstats" local wood = Instance.new("IntValue", player) wood.Name = "Wood" wood.Value = 0 wood.Parent = leaderstats local stone = Instance.new("IntValue", player) stone.Name = "Stone" stone.Value = 0 stone.Parent = leaderstats end)
Script 2 -
game.Workspace.Tree.ClickDetector.MouseClick:connect(function() game.Players.LocalPlayer.leaderstats.Wood.Value = game.Players.LocalPlayer.leaderstats.Wood.Value + 1 end)
Script 3 -
local clickdetector = game.Workspace.Tree.ClickDetector clickdetector.MouseClick:Connect(function() game.Workspace.TreeCutting:FireServer() end)
Any help will be appreciated!
So don't add FE for Mouse click as long as everything is done in Script As far as I know mouse click don't need a Remote Event.
You were missing to parent leaderstat.
game.Players.PlayerAdded:connect(function(player) local leaderstats = Instance.new("Folder", player) leaderstats.Name = "leaderstats" local wood = Instance.new("IntValue", player) wood.Name = "Wood" wood.Value = 0 wood.Parent = leaderstats local stone = Instance.new("IntValue", player) stone.Name = "Stone" stone.Value = 0 stone.Parent = leaderstats leaderstats.Parent = player --You were missin this end) --RiskoZoSlovenska saw that so second script should be
Script 2
RiskoZoSlovenska noticed that. So second script should be.
game.Workspace.Tree.ClickDetector.MouseClick:connect(function(player) player.leaderstats.Wood.Value = player.leaderstats.Wood.Value + 1 end)
Well let's look at what happens. Script 1 is run when a player joins, and so there shouldn't be anything wrong with that. Script 3 fires the TreeCutting event to the server. Script 2 does whatever when the ClickDetector is clicked. However, I see several problems here. First of all, script 2 is a Script, and you need a LocalScript to be able to call LocalPlayer. Second, nothing receives the TreeCutting event. Try something like this: Script 1: Script 1 should be a Script placed into Tree
local detec = script.Parent.ClickDetector detec.MouseClick:Connect(function(playerWhoClicked) game.Workspace.TreeCutting:FireClient(playerWhoClicked) )
This will fire an event to each player who clicked the detector. Then make a script (LocalScript, i believe) inside the player which will receive the event and act upon it. I"m not a professional Lua Scripter, so I probably messed up somewhere, but I think something like this could work. If not, tell me and I'll try to fix it.