when I touch the object, I want it to be deleted and come back after 2 seconds and add 1 coin. how can I do this?
local WheatAmount = script.Parent
local oyuncuParasi = "Coins"
duvar = false
function onTouch(vurus)
if duvar == false then
oyuncuParasi = oyuncuParasi +1;
duvar = true
vurus.Parent:Destroy()
WheatAmount.CanCollide = false
wait(2)
WheatAmount.CanCollide = true
duvar = false
end
end
script.Parent.Touched:connect(onTouch)
You are trying to add 1 to local oyuncuParasi = "Coins" which is currently a string...
Try this:
local WheatAmount = script.Parent
local oyuncuParasi = 0
duvar = false
function onTouch(vurus)
if duvar == false then
oyuncuParasi += 1; -- Adds a coin
duvar = true
WheatAmount.Transparent = 1 -- Set the object Transparent
WheatAmount.CanCollide = false
WheatAmount.CanTouch = false
wait(2)
WheatAmount.Transparent = 0 -- Set the object Not Transparent
WheatAmount.CanCollide = true
WheatAmount.CanTouch = true
duvar = false
end
end
script.Parent.Touched:connect(onTouch)
Note: Make sure you put this in a server sided script instead of local script in the Object.
Let me know if it worked and the results!!
Related
I don't know what's happening, but i'm getting that error in output. Apparently every animations of the Anims table and normalcombo table exists, and the property too. I tested it in Commandbar but didn't work. I don't know how to fix it and don't know what's the problem. Please help me. Code below:
--Local Script
local Replicated = game:GetService("ReplicatedStorage")
local UIS = game:GetService("UserInputService")
local Remote = Replicated.CombateEvent
local Player = game.Players.LocalPlayer
local Char = Player.CharacterAdded:Wait()
local Humanoid = Char:WaitForChild("Humanoid")
local istoolequipped = false
script.Parent.Equipped:Connect(function()
istoolequipped = true
end)
script.Parent.Unequipped:Connect(function()
istoolequipped = false
end)
local lastM1Time = 0
local lastM1End = 0
local combo = 1
local canAir = true
local Anims = {
"rbxassetid://12270296026",
"rbxassetid://12290262661",
"rbxassetid://12290234803",
}
local normalcombo = {
"rbxassetid://12303443278",
"rbxassetid://12303443278",
"rbxassetid://12303527113",
"rbxassetid://12303770582"
}
function hb(size, cframe, ignore, char)
local hitbox = Instance.new("Part", workspace)
hitbox.Size = size
hitbox.CFrame = cframe
hitbox.Anchored = true
hitbox.CanCollide = false
hitbox.Transparency = .6
hitbox.Name = "hb"
hitbox.Material = Enum.Material.ForceField
hitbox.CanQuery = false
local connection
connection = hitbox.Touched:Connect(function()
connection:Disconnect()
end)
local lasttarget
for _, v in pairs(hitbox:GetTouchingParts()) do
if v.Parent:FindFirstChild("Humanoid") and table.find(ignore, v.Parent.Name) == nil then
if lasttarget then
if (lasttarget.Position - char.PrimaryPart.Position).Magnitude > (v.Position - char.PrimaryPart.Position).Magnitude then
lasttarget = v.Parent.PrimaryPart
end
else
lasttarget = v.Parent.PrimaryPart
end
end
end
hitbox:Destroy()
if lasttarget then
return lasttarget.Parent
else
return nil
end
end
UIS.InputBegan:Connect(function(input, istyping)
if istyping then return end
if input.UserInputType == Enum.UserInputType.MouseButton1 and tick() - lastM1Time > .3 and tick() - lastM1End > .7 and istoolequipped then
if tick() - lastM1Time > .7 then
combo = 0
end
lastM1Time = tick()
local animation = Instance.new("Animation", workspace.Animation)
local air = nil
if UIS:IsKeyDown("Space") and canAir == true and combo == 2 then
canAir = false
air = "Up"
animation.AnimationId = Anims[1]
elseif UIS:IsKeyDown("Space") and combo == 3 and not canAir then
air = "Down"
animation.AnimationId = Anims[2]
else
animation.AnimationId = normalcombo[combo]
end
local load = Humanoid:LoadAnimation(animation)
load:Play()
animation:Destroy()
local hitTarg = hb(Vector3.new(3,5,3), Char.PrimaryPart.CFrame * CFrame.new(0,0,-3), {Char}, Char)
local Info = {
["Target"] = hitTarg,
["Combo"] = combo,
["Character"] = Char,
["Air"] = air
}
Remote:FireServer("Combo", Info)
if combo == #normalcombo then
combo = 1
lastM1End = tick()
else
combo += 1
end
Humanoid.WalkSpeed = 0
task.wait(.4)
Humanoid.WalkSpeed = 16
end
end)
The error send me to this line: "animation.AnimationId = normalcombo[combo]"
The error is telling you that normalcombo[combo] is returning nil when it should be a content url. That means that combo isn't a value between 1 and #normalcombo (4).
The only place where that could be is here :
if tick() - lastM1Time > .7 then
combo = 0
end
Here you are resetting the combo counter, but you set it too low. Arrays in lua are 1-indexed. You need to set it to :
combo = 1
Good day,
i have the problem that i wana make my visit ui only visible when i am at spawn so at first i wanted to do it with checking the team but i dont found any solousion on how to check which player is in which and than disable/enable ui for them. So after this i made an bool inside of the ui named Loby and got it to work that it turns on / off based on where you are but the problem is that i dont get the ui working i tried this now for serveral hours but i just dont get it and i dont know why. Its only prints not in Loby else if im in Loby or in a round ;(, i hope someone can help me!, Good day
FyMa2618
local loby = script.Parent.Loby
while loby.Value == false do
print("Not In Lobby")
script.Parent.Enabled = false
wait(.1)
end
while loby.Value == true do
local ready = script.Parent.Loaded
print("Lobby is Active")
script.Parent.Enabled = true
wait(.1)
end
--its a local script in the same position as the Bool.
The round script(nedded for the bool)
local intermission = 25
local roundLength = 45
local inRound = game.ReplicatedStorage.InRound
local staus = game.ReplicatedStorage.Status
-- when round value is changed
inRound.Changed:Connect(function()
if inRound.Value == false then
for i, plr in pairs(game.Players:GetChildren()) do
local char = plr.Character
local humanRoot = char:WaitForChild("HumanoidRootPart")
humanRoot.CFrame = game.Workspace.lobbySpawn.CFrame
end
end
end)
-- changes the status
local function round()
while true do
inRound.Value = false
for i = intermission, 0, -1 do
staus.Value = "Game will start in "..i.." seconds"
wait(1)
end
inRound.Value = true
wait(3)
for i = roundLength, 0, -1 do
wait(1)
staus.Value = "Game will end in "..i.." seconds"
local playing = {}
for i, plr in pairs(game.Players:GetChildren()) do
if plr.Team.Name == "Playing" then
local b = game.StarterGui.SpectateGUI.Loby
b.Value = false
table.insert(playing, plr.Name)
print("inserted player")
end
end
if #playing == 0 then
staus.Value = "Everyone Has Died"
wait(3)
break
end
end
end
end
The Region 3 Code(also needed for the bool)
local RegionPart = game.Workspace.RegionPart
local pos1 = RegionPart.Position - (RegionPart.Size / 2)
local pos2 = RegionPart.Position + (RegionPart.Size / 2)
local region = Region3.new(pos1, pos2)
--[[
local part = Instance.new("Part")
part.Anchored = true
part.Size = region.Size
part.Parent = game.Workspace
part.CanCollide = false
part.Transparency = 0.4
dont worry about this
]]--
while true do
wait()
local partsInRegion = workspace:FindPartsInRegion3(region, nil, 1000)
for i, part in pairs(partsInRegion) do
if part.Parent:FindFirstChild("Humanoid") ~= nil then
local char = part.Parent
local loby = game.StarterGui.SpectateGUI.Loby
loby.Value = true
end
end
end[Starter UI][1]
basically after my math.random it will teleport you to a location and then after 20 seconds it will teleport you back. The proximity prompt that this script is in only fires this script once, i click the button to go to sleep and it does nothing, no error code no thing. On the other hand after the else statement i can click the button three separate times and then if i try clicking it a fourth time it no longer works, still with no error.
Is there anyway I can fix this?
Heres my code if helpful
game.Players.PlayerAdded:Connect(function(player)
script.Parent.Triggered:Connect(function(activated)
if activated then
print("activated")
if game.ReplicatedFirst.night.Value == true then
script.Parent.Enabled = false
local number = math.random(1, 2)
print(number)
if number == 1 then
local plr = game.Workspace:FindFirstChild(player.Name)
game.ReplicatedFirst.slep.Value = true
plr.Humanoid.HipHeight = -0.913
plr.HumanoidRootPart.Position = Vector3.new(327.227, 1.5, -348.899) + Vector3.new(0,10,0)
print("ho")
player.PlayerGui.slepgui.Enabled = false
wait(20)
game.Workspace:FindFirstChild(player.Name).HumanoidRootPart.Position = Vector3.new(31.546, 20.793, 12.62) + Vector3.new(0,10,0)
script.Parent.Enabled = true
game.ReplicatedFirst.night.Value = false
game.ReplicatedFirst.slep.Value = false
game.Workspace["Hotel - undertale"].Playing = true
game.Lighting.TimeOfDay = 12
else
local plr = game.Workspace:FindFirstChild(player.Name)
player.PlayerGui.slepgui.Enabled = true
script.Parent.Enabled = false
game.ReplicatedFirst.slep.Value = true
script.Parent.ObjectText = "Go to bed, this will skip the night"
game.Workspace["SNORING - SOUND EFFECT (128 kbps)"].Playing = true
print("number one worked")
wait(12)
plr.HumanoidRootPart.Position = Vector3.new(31.546, 20.793, 12.62) + Vector3.new(0,10,0)
game.ReplicatedFirst.night.Value = false
game.ReplicatedFirst.slep.Value = false
game.Workspace["Hotel - undertale"].Playing = true
player.PlayerGui.slepgui.Enabled = false
script.Parent.Enabled = true
game.Lighting.TimeOfDay = 12
script.Parent.ObjectText = "Go to bed. Only avaliable at night"
print("Numver two worked")
end
end
end
end)
end)
-- 327.227, 1.5, -348.899
I tried a Gates Script but the script works fine but the 2nd Remote Event doesnt like to fire. It does nothing.
--This Works Fine
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("HalloweenGatesTakeMoney")
local Price = script.Parent:WaitForChild("Price").Value
script.Parent.MouseButton1Click:Connect(function(player)
script.Parent.Parent.Visible = false
script.Parent.Parent.Parent.Shadow.Visible = false
local GateName = script.Parent:WaitForChild("Gate").Value
GateName:Destroy()
remoteEvent:FireServer(Price)
end)
--But this does nothing
remoteEvent2.OnServerEvent:Connect(function(player, Price)
player.EventMoney.Sweets.Value = player.EventMoney.Sweets.Value - Price
wait(1)
if player.PlayerGui:WaitForChild("HalloweenGates").Frame.Buy.GateValueName == "HauntedEntrance" then
player:WaitForChild("HalloweenGates").HauntedEntrance.Value = true
elseif player.PlayerGui:WaitForChild("HalloweenGates").Frame.Buy.GateValueName == "PumpkinCave" then
player:WaitForChild("HalloweenGates").PumpkinCave.Value = true
elseif player.PlayerGui:WaitForChild("HalloweenGates").Frame.Buy.GateValueName == "HauntedBiome" then
player:WaitForChild("HalloweenGates").HauntedBiome.Value = true
elseif player.PlayerGui:WaitForChild("HalloweenGates").Frame.Buy.GateValueName == "GiantPumpkin" then
player:WaitForChild("HalloweenGates").GiantPumpkin.Value = true
end
end)
--Full script of above
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("HalloweenGates")
local remoteEvent2 = ReplicatedStorage:WaitForChild("HalloweenGatesTakeMoney")
remoteEvent.OnServerEvent:Connect(function(player, Price, GateName, GateValue)
if player.EventMoney.Sweets.Value >= Price then
player.PlayerGui.HalloweenGates.Frame.Visible = true
player.PlayerGui.HalloweenGates.Shadow.Visible = true
player.PlayerGui.HalloweenGates.Frame.Price.Text = "This Gate costs "..Price.." Sweets"
player.PlayerGui.HalloweenGates.Frame.Buy.Gate.Value = GateName
player.PlayerGui.HalloweenGates.Frame.Buy.Price.Value = Price
player.PlayerGui.HalloweenGates.Frame.Buy.GateValueName.Value = GateValue
end
end)
remoteEvent2.OnServerEvent:Connect(function(player, Price)
player.EventMoney.Sweets.Value = player.EventMoney.Sweets.Value - Price
wait(1)
if player.PlayerGui:WaitForChild("HalloweenGates").Frame.Buy.GateValueName == "HauntedEntrance" then
player:WaitForChild("HalloweenGates").HauntedEntrance.Value = true
elseif player.PlayerGui:WaitForChild("HalloweenGates").Frame.Buy.GateValueName == "PumpkinCave" then
player:WaitForChild("HalloweenGates").PumpkinCave.Value = true
elseif player.PlayerGui:WaitForChild("HalloweenGates").Frame.Buy.GateValueName == "HauntedBiome" then
player:WaitForChild("HalloweenGates").HauntedBiome.Value = true
elseif player.PlayerGui:WaitForChild("HalloweenGates").Frame.Buy.GateValueName == "GiantPumpkin" then
player:WaitForChild("HalloweenGates").GiantPumpkin.Value = true
end
end)
--Here's where I fire the remoteEvent2 event
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("HalloweenGatesTakeMoney")
local Price = script.Parent:WaitForChild("Price").Value
script.Parent.MouseButton1Click:Connect(function(player)
script.Parent.Parent.Visible = false
script.Parent.Parent.Parent.Shadow.Visible = false
local GateName = script.Parent:WaitForChild("Gate").Value
GateName:Destroy()
remoteEvent:FireServer(Price)
end)
I made a gun shop website. When I try to buy a gun the first time it works but, when I delete the gun from my inventory and try again it wont work.
Please Help.
local ServerStorage = game:GetService("ServerStorage")
local Vendedor = script.Parent
local ClickDetector = game.Workspace.Lojadearmas.Vendedor.ClickDetector
local Glock = ServerStorage:WaitForChild("G17"):Clone()
ClickDetector.MouseClick:Connect(function(player)
print(player.name)
local Player = player
local Gui = player.PlayerGui.LojaArmas
Gui.Frame.Visible = true
Gui.Frame2.Visible = true
Gui.Glock.Visible = true
Gui.Fechar.Visible = true
Gui.Loja.Visible = true
Gui.Fechar.MouseButton1Click:Connect(function()
Gui.Frame.Visible = false
Gui.Frame2.Visible = false
Gui.Glock.Visible = false
Gui.Fechar.Visible = false
Gui.Loja.Visible = false
print(Player)
end)
Gui.Glock.MouseButton1Click:Connect(function()
if Player.leaderstats.Reais.Value >= 1000 then
Glock.Parent = Player.Backpack
print(Player.leaderstats.Reais.Value)
Player.leaderstats.Reais.Value = Player.leaderstats.Reais.Value - 1000
end
end)
end)
Its because you are cloning it once when you referenced the variable Glock. Try this:
local ServerStorage = game:GetService("ServerStorage")
local Vendedor = script.Parent
local ClickDetector = game.Workspace.Lojadearmas.Vendedor.ClickDetector
local Glock = ServerStorage:WaitForChild("G17")
ClickDetector.MouseClick:Connect(function(player)
print(player.name)
local Player = player
local Gui = player.PlayerGui.LojaArmas
Gui.Frame.Visible = true
Gui.Frame2.Visible = true
Gui.Glock.Visible = true
Gui.Fechar.Visible = true
Gui.Loja.Visible = true
Gui.Fechar.MouseButton1Click:Connect(function()
Gui.Frame.Visible = false
Gui.Frame2.Visible = false
Gui.Glock.Visible = false
Gui.Fechar.Visible = false
Gui.Loja.Visible = false
print(Player)
end)
Gui.Glock.MouseButton1Click:Connect(function()
if Player.leaderstats.Reais.Value >= 1000 then
Glock:Clone().Parent = Player.Backpack
print(Player.leaderstats.Reais.Value)
Player.leaderstats.Reais.Value = Player.leaderstats.Reais.Value - 1000
end
end)
end)
Let me know if you require any further assistance.