Hello! I’m trying to convert two scripts into local ones, since they both run on the server when I want them to run locally.
The issue is that, well, I can’t really get it to work, as I don’t know how. Sorry if this topic seems kind of vague, I just can’t really figure anything out right now.
Scripts:
--corn gen script
print("Running")
local RepStorage = game:GetService("ReplicatedStorage")
local cornamount = RepStorage:WaitForChild("cornamount")
local module = require(RepStorage:WaitForChild("ModuleScript"))
local dirt = game.Workspace.dirt
local corn = RepStorage:WaitForChild("corn")
local function addcorn()
wait(module.waitTime)
local corn2 = corn:Clone()
corn2.Parent = game.Workspace
corn2.Transparency = 0
local randomVal = math.random(1,2)
if randomVal == 1 then
local x = math.random(-37,37)
local z = math.random(-37,37)
corn2.Position = dirt.Position + Vector3.new(x, dirt.Size.Y, z)
elseif randomVal == 2 then
local x = math.random(-37,37)
local z = math.random(-37,37)
corn2.Position = dirt.Position - Vector3.new(x, -dirt.Size.Y, z)
end
cornamount.Value = cornamount.Value + 1
end
while true do
if cornamount.Value <= module.CornCap then
addcorn()
else
wait()
end
end
--Basically what happens if the corn is touched
local Players = game:GetService("Players")
local corn = script.Parent
local RepStorage = game:GetService("ReplicatedStorage")
local SGui = game:GetService("StarterGui")
local cornamount = RepStorage:WaitForChild("cornamount")
local cornamountLabel = SGui.GameStats.Frame.Frame:WaitForChild("cornamountlabel")
local module = require(RepStorage:WaitForChild("ModuleScript"))
corn.Touched:Connect(function(hit)
local player = Players:GetPlayerFromCharacter(hit.Parent)
if player then
corn:Destroy()
cornamount.Value = cornamount.Value - 1
local leaderstats = player.leaderstats
local cornStat = leaderstats:FindFirstChild("corn")
if cornStat then
cornStat.Value = cornStat.Value + module.cornVal
end
end
end)
Also, first thing first, All the contents in StarterGui will be automatically place in game.Players.LocalPlayer.PlayerGui. If you want to use it, please refer to this instead.
Okay, so the first script might be working fine as a localscript, but I’m still not fully sure. The 2nd script doesn’t work as a localscript because it never even runs.
You should also notice that you need to change a player’s value through the server in case you want to datastore it (since DataStoreService only runs on server).
If that’s not the issue, then just debug your 2nd script using print() on different states of your code!
Ahh, I’m pretty sure i found the root of the problem. Since the part is created with a localscript, I can’t run a .touched event because it only works on server scripts or if a part was created by the server
The first script is working fine, though. @Corruptux@Jacky2804@kokirimagic