Before it used 6 lines per Scripts for the Food-Things but now, I made some changes that would need more lines (up to 20 lines now!)
But uh… It’s strange… I didn’t touch anything but now it works, it’s not a string but a Instance now!
I just deleted the print() line!
For the time being revert to the old system with the shorter scripts to make sure the actual destroy function is still working, I’d then add each feature that you want while testing it so you can pin point the error.
I just deleted the print() line and then:
Succefully fired the new event 7 from Leolol_DB
IT WORKS!
Okay can you show me the script before you deleted the print?
Uh… I must do Ctrl+Z?
The entire Script, it’s used for all Client to Server communications
local RS = game:GetService("ReplicatedStorage")
local NewEvent = RS:WaitForChild("NewEvent")
NewEvent.OnServerEvent:Connect(function(Plr,Event,Data)
local DF = Plr.DataF
local OK, Err = pcall(function()
if Event==1 then
DF.Stats.MoveSpeed.Value = Data
elseif Event==2 then
print("Event 2 caught")
elseif Event==3 then
DF.ProgrS.Level.Value = DF.ProgrS.Level.Value + 1
DF.Status.Dirt.Value = DF.Status.Dirt.Value + 1
DF.Status.LV3Energy.Value = DF.Status.LV3Energy.Value - (Plr.DataF.Stats.Intake.Value*2)
elseif Event==4 then
local i=0
for i=1,9 do
Plr.DataF.Stats[Data[i*2-1]].Value = Data[i*2]
end
elseif Event==5 then
DF.Stats.Level.Value = Data[1]
DF.ProgrS.Level.Value = Data[2]
elseif Event==6 then
if Data[1]==1 then
game.Workspace.Hobby.AdminModRoom.LoudSpeaker.Box.GUI.Id.Text = Data[2]
elseif Data[1]==2 then
game.Workspace.Hobby.AdminModRoom.LoudSpeaker.On.Value = Data[2]
end
elseif Event==7 then
DF.Status.Food.Value = DF.Status.Food.Value + Data[1]
print(typeof(Data[2]))
Data[2]:Destroy()
elseif Event==8 then
print("Event 8 caught")
elseif Event==9 then
print(Data)
NewEvent:FireClient(Plr,3,"PONG!")
elseif Event==10 then
else
error("Unavailable event")
end
end)
if OK then
print("Succefully fired the new event "..Event.." from "..Plr.Name)
else
print("Error while firing a new event (event "..Event..") from "..Plr.Name.."\n"..Err)
end
end)
It’s from ‘elseif Event==7 then’ for the food
The event 10 is in Work
Mk I’ll read through it tonight when I get back onto PC, for the time being you can leave the print() bit out so it works. I’ll then read through and try to identify any errors.
Can you show us the local script? So we can know what is Data[2].
Yes! Here’s the ENTIRE Script:
local Plr = script.Parent.Parent
local Cursor = Plr:GetMouse()
local DataF = Plr:WaitForChild("DataF")
local Mode = DataF:WaitForChild("Mode")
local IObj = {"MiniBurgerThing",2,"MiniCaviarToast",2,"MiniTomatoToast",2,"MeatyThing",2,"Cup",3,"PowerLSButton",4,"PauseLSButton",4}
local RS = game:GetService("ReplicatedStorage")
local NewEvent = RS:WaitForChild("NewEvent")
local DiGV = DataF.ProgrS.Digging
local Status = DataF.Status
local Beam = false
local NCLBU = false
local NCLBD = false
local CLBD = false
local Enable = true
local function DistCalc(Pos1,Pos2)
local Pos = Pos2 - Pos1
return math.sqrt(Pos.X*Pos.X+Pos.Y*Pos.Y+Pos.Z*Pos.Z)
end
local function DoAct(Object,ObjNum)
local Action = IObj[ObjNum*2]
local OK,Err = pcall(function()
if Action==1 then
--How can you dig IObj?
elseif Action==2 then
local FoodV = Status.Food
local Nut = {48,32,24,16}
if FoodV.Value <= (256-Nut[ObjNum]) then
FoodV.Value = FoodV.Value + Nut[ObjNum]
NewEvent:FireServer(7,{Nut[ObjNum],Object})
end
elseif Action==3 then
--Take
elseif Action==4 then
if ObjNum==6 then
NewEvent:FireServer(6,{2,not game.Workspace.Hobby.AdminModRoom.LoudSpeaker.On.Value})
end
end
end)
if not OK then
print("Error while doing Mouse Action "..Action.." with "..IObj[ObjNum*2-1].."\n"..Err)
end
end
while Plr.Character == nil do
wait(0.1)
end
local CursorAtt = Instance.new("Attachment",Plr.Character:WaitForChild("HumanoidRootPart"))
CursorAtt.Name = "Cursor"
Plr.Character.ChildRemoved:Connect(function()
Plr.Character:WaitForChild("Beam",4)
end)
Cursor.Button1Down:Connect(function()
NCLBD = true
CLBD = true
end)
Cursor.Button1Up:Connect(function()
NCLBU = true
CLBD = false
end)
while true do
if Beam then
Beam.Visible = false
end
CursorAtt.WorldPosition = Cursor.Hit.Position
local Targ = Cursor.Target
if Mode.Value == "Idle" then
if not (Targ == nil) then
local T = Targ.Name
local M = Targ.Parent.Name
local C = {"Dig","Eat","Take","Use"}
local i=0
Cursor.Icon = ""
for i=1,#IObj,2 do
if IObj[i] == M then --or ObjC[i] == T
if DistCalc(Plr.Character.PrimaryPart.Position,Targ.Position) <= 8 then
Cursor.Icon = "rbxgameasset://Images/"..C[IObj[i+1]].."Cursor"
if NCLBU then
DoAct(Targ.Parent,(i+1)/2)
end
end
break
end
end
end
NCLBD = false
NCLBU = false
else
if CLBD then
if (not (Targ == nil))and Mode.Value == "Dig" and Targ.Parent.Parent.Name == "Dirt" and DistCalc(Plr.Character.PrimaryPart.Position,Targ.Position)-Targ.Size.Y <= 16 then
Cursor.Icon = "rbxgameasset://Images/DigCursor"
local StrgNum,CLBD = string.gsub(Targ.Name,"Dirt","")
CLBD = true
Number = tonumber(StrgNum)
if Targ.Parent.Name == "t1" then
if DiGV.Value >= 256 then
NewEvent:FireServer(3,Number)
DiGV.Value = 0
end
else
NewEvent:FireServer(2,{Targ.Size.Y,Number})
end
if DiGV.Value >= 256-DataF.Stats.Dig.Value/8 then
DiGV.Value = 256
elseif Status.LV3Energy.Value >= DataF.Stats.Intake.Value*2 then
DiGV.Value = DiGV.Value + DataF.Stats.Dig.Value/8
if Beam then
Beam.Color = Color3.new(1,0.5,0)
Beam.Visible = true
end
end
else
if DiGV.Value > 0 then
Cursor.Icon = ""
DiGV.Value = 0
end
end
else
if NCLBU then
Cursor.Icon = ""
DiGV.Value = 0
NCLBU = false
end
NCLBD = false
end
end
wait()
end
The Script is doing all things I need for the Cursor, so there is a part for digging eating and others!
Here a “summary” of it
local Plr = script.Parent.Parent
local Cursor = Plr:GetMouse()
local DataF = Plr:WaitForChild("DataF")
local Mode = DataF:WaitForChild("Mode")
local IObj = {"MiniBurgerThing",2,"MiniCaviarToast",2,"MiniTomatoToast",2,"MeatyThing",2,"Cup",3,"PowerLSButton",4,"PauseLSButton",4}
local RS = game:GetService("ReplicatedStorage")
local NewEvent = RS:WaitForChild("NewEvent")
local DiGV = DataF.ProgrS.Digging
local Status = DataF.Status
local NCLBU = false
local NCLBD = false
local CLBD = false
local Enable = true
local function DistCalc(Pos1,Pos2)
local Pos = Pos2 - Pos1
return math.sqrt(Pos.X*Pos.X+Pos.Y*Pos.Y+Pos.Z*Pos.Z)
end
local function DoAct(Object,ObjNum)
local Action = IObj[ObjNum*2]
local OK,Err = pcall(function()
if Action==1 then
--How can you dig IObj?
elseif Action==2 then
local FoodV = Status.Food
local Nut = {48,32,24,16}
if FoodV.Value <= (256-Nut[ObjNum]) then
FoodV.Value = FoodV.Value + Nut[ObjNum]
NewEvent:FireServer(7,{Nut[ObjNum],Object})
end
elseif Action==3 then
--Take
elseif Action==4 then
--Use
end
end)
if not OK then
print("Error while doing Mouse Action "..Action.." with "..IObj[ObjNum*2-1].."\n"..Err)
end
end
while Plr.Character == nil do
wait(0.1)
end
local CursorAtt = Instance.new("Attachment",Plr.Character:WaitForChild("HumanoidRootPart"))
CursorAtt.Name = "Cursor"
Plr.Character.ChildRemoved:Connect(function()
Plr.Character:WaitForChild("Beam",4)
end)
Cursor.Button1Down:Connect(function()
NCLBD = true
CLBD = true
end)
Cursor.Button1Up:Connect(function()
NCLBU = true
CLBD = false
end)
while true do
--
local Targ = Cursor.Target
if Mode.Value == "Idle" then
if not (Targ == nil) then
local T = Targ.Name
local M = Targ.Parent.Name
local C = {"Dig","Eat","Take","Use"} --Define Actions names
local i=0
Cursor.Icon = "" --Reset Cursor's Icon
for i=1,#IObj,2 do
if IObj[i] == M then --or ObjC[i] == T --It try to find M in IObj
if DistCalc(Plr.Character.PrimaryPart.Position,Targ.Position) <= 8 then --If it's too far away, it will not activate but it break!
Cursor.Icon = "rbxgameasset://Images/"..C[IObj[i+1]].."Cursor" --Set cursor's Icon
if NCLBU then
DoAct(Targ.Parent,(i+1)/2)
end
end
break
end
end
end
NCLBD = false
NCLBU = false
else
if CLBD then
if (not (Targ == nil))and Mode.Value == "Dig" and Targ.Parent.Parent.Name == "Dirt" and DistCalc(Plr.Character.PrimaryPart.Position,Targ.Position)-Targ.Size.Y <= 16 then
--Dig
else
--Stop digging
end
else
if NCLBU then
Cursor.Icon = ""
DiGV.Value = 0
NCLBU = false
end
NCLBD = false
end
end
wait()
end