I own a simulator with 0 active that has Clicks. When I upgrade too much, my clicks get negative amount of clicks at a few quintillions (10^18), abbreviations work until decillions. (10^33). How do I make that clicks will not turn negative or something else wrong will happen with their value when I reach over a few quintillions?
Leaderstats Script (game.Workspace):
game.Players.PlayerAdded:Connect(function(plr)
local leaderstats = Instance.new("IntValue",plr)
leaderstats.Name = "leaderstats"
local Clicks = Instance.new("IntValue",leaderstats)
Clicks.Name = "Clicks"
local Power = Instance.new("IntValue",leaderstats)
Power.Name = "Power"
Power.Value = 1
local SC = Instance.new("IntValue",leaderstats)
SC.Name = "SuperClicks"
local MC = Instance.new("IntValue",leaderstats)
MC.Name = "MegaClicks"
local SCC = Instance.new("IntValue",leaderstats)
SCC.Name = "SuperClicksChance"
SCC.Value = 10
local MCC = Instance.new("IntValue",leaderstats)
MCC.Name = "MegaClicksChance"
MCC.Value = 1
local ODMG = Instance.new("IntValue",leaderstats)
ODMG.Name = "OreDamage"
ODMG.Value = 1
local SP = Instance.new("IntValue",leaderstats)
SP.Name = "SuperPower"
SP.Value = 1
local MP = Instance.new("IntValue",leaderstats)
MP.Name = "MegaPower"
MP.Value = 1
local Gems = Instance.new("IntValue",leaderstats)
Gems.Name = "Gems"
local OD = Instance.new("IntValue",leaderstats)
OD.Name = "OreDamage"
OD.Value = 1
if Clicks.Value >= (9 * (10 ^ 17)) then
Clicks.Value = 0
Power.Value = 1
end
end)
Everything works, but I also made that if I get 900 quadrillion clicks, my power and clicks will reset. But I don't want that. I want atleast to know how to create a stat with amount of zeros in my clicks. If it will work, I will make that in GUI Counter will be shown like this: 10^x (x = amount of zeros)
Also, if you want to try my simulator, here's the link:
Click Simulator Beta 0.31
Related
I'm trying to slice a part of this part, so that it matches the bottom part, and the method I'm trying is SubtractAsync.
When I do it however, the part gets sliced, but not so that the remaining part gets removed. Here's what I mean:
How do I edit my code to slice off the piece of the part?
My code:
local Brick = workspace.Brick
local Stack = Brick:Clone()
local TS = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(3, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut, math.huge, true)
Stack.Position = Vector3.new(Brick.Position.X, Brick.Position.Y + Brick.Size.Y, Brick.Position.Z - 55)
local tween = TS:Create(Stack, tweenInfo, {Position = Vector3.new(Stack.Position.X, Stack.Position.Y, Stack.Position.Z + (55 * 2))})
Stack.Parent = workspace
tween:Play()
game.ReplicatedStorage.PlaceDown.OnServerEvent:Connect(function()
tween:Pause()
local PartA = Instance.new("Part")
local PartB = Instance.new("Part")
PartA.Transparency = 1
PartB.Transparency = 1
PartA.Parent = workspace
PartB.Parent = workspace
PartA.Orientation = Vector3.new(-90, 0, 0)
PartB.Orientation = Vector3.new(-90, 0, 0)
PartA.Size = Vector3.new(15, 0.051, 15)
PartB.Size = Vector3.new(15, 0.051, 15)
PartA.Position = Vector3.new(Brick.Position.X, Brick.Position.Y + 2.5, Brick.Position.Z - (Brick.Size.Z/2))
PartB.Position = Vector3.new(Brick.Position.X, Brick.Position.Y + 2.5, Brick.Position.Z + (Brick.Size.Z/2))
PartA.Anchored = true
PartB.Anchored = true
local SlicedStack = Stack:SubtractAsync({PartA, PartB})
SlicedStack.Position = Stack.Position
SlicedStack.Parent = workspace
Stack:Destroy()
PartA:Destroy()
PartB:Destroy()
end)
I'm trying(I'm very new) to make a game where you have to attack each other with a boat. There is a button on each island and when you press it, a boat should appear. (this works so far)
But as soon as you want to spawn a new boat it removes everyones boat. I thought it makes sense to use player.id but this still won't work. Does anyone know the solution?
Below you will find the code thats hidden in a part.
Thanks!
CODE:
local cd = script.Parent.ClickDetector
local boat = script.Parent.Parent.Firstboat
local button = script.Parent
local debounce = false
game.Players.PlayerAdded:Connect(function(player)
print(player.UserId)
local plruserid = player.UserId
print(player.Name)
boat.Parent = game.ServerStorage
cd.MouseHoverEnter:Connect(function()
button.Transparency = 0.5
end)
cd.MouseHoverLeave:Connect(function()
button.Transparency = 0
end)
cd.MouseClick:Connect(function()
local SetNameToBoat = plruserid
print (SetNameToBoat)
local oldboat = workspace:FindFirstChild(SetNameToBoat)
if not debounce then
if oldboat then
oldboat : destroy()
end
debounce = true
local NewBoat = boat:clone()
NewBoat.Name = (SetNameToBoat)
NewBoat.Parent = game.Workspace
wait(5)
debounce = false
end
end)
end)
I simplified the code and found the solution:
local cd = workspace.Button:WaitForChild('ClickDetector')
local boat = game:GetService('ServerStorage'):WaitForChild('Boat')
local button = workspace:WaitForChild('Button')
local debounce = false
cd.MouseHoverEnter:Connect(function()
button.Transparency = 0.5
end)
cd.MouseHoverLeave:Connect(function()
button.Transparency = 0
end)
cd.MouseClick:Connect(function(player)
local plruserid = player.UserId
local SetNameToBoat = plruserid
print(SetNameToBoat)
local oldboat = workspace:FindFirstChild(SetNameToBoat)
if not debounce then
if oldboat then
oldboat:destroy()
end
debounce = true
local NewBoat = boat:clone()
NewBoat.Name = SetNameToBoat
NewBoat.Parent = game.Workspace
wait(5)
debounce = false
end
end)
so there are 2 scripts: script and localscript.
The script determines how many seconds there will be and then it fires it to all player clients & the localscript changes the text to seconds. But when i tested the game the countdow freezes either at a number or a random number anyway here's the script again:
script:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("IntermissonEvent")
local secondsRemaining = 15
for t = secondsRemaining, 0, -1 do
remoteEvent:FireAllClients(t)
wait(1)
end
localscript:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("IntermissonEvent")
local function onTimerUpdate(seconds)
script.Parent.Text =(seconds)
wait(15)
script.Parent.Parent.CountdownText.Visible = false
script.Parent.Parent.IntermissionText.Visible = false
script.Parent.Parent.TextLabel.Text ="Vote for a Map!"
script.Parent.Parent.MapVotingFrame.Visible = true
end
remoteEvent.OnClientEvent:Connect(onTimerUpdate)
Your LocalScript is running all of this logic every single time the server fires the event. Instead of waiting, check the value with an if-then.
local function onTimerUpdate(seconds)
script.Parent.Text = tostring(seconds)
if seconds == 0 then
script.Parent.Parent.CountdownText.Visible = false
script.Parent.Parent.IntermissionText.Visible = false
script.Parent.Parent.TextLabel.Text = "Vote for a Map!"
script.Parent.Parent.MapVotingFrame.Visible = true
end
end
I'm trying to reward the player with exp every time they the punch a damageable object (punching bag, dummies, etc) Whenever the play punches something, it updates the exp leaderstat only once, does anyone know what i'm doing wrong?
My Script:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
script.Parent.Touched:Connect(function(hit)
local Char = hit.parent
local Hum = Char:FindFirstChild("Humanoid")
if Hum and Char.Name ~= script.Parent.Parent.Name then
local Indicator = require(game.ReplicatedStorage.DamageIndicator)
local Player = script.Parent.Parent
local LocalPlayer = game.Players:GetPlayerFromCharacter(Player)
local Exp = LocalPlayer.leaderstats.Experience.Value
Hum:TakeDamage(script.Dmg.Value)
Indicator.DamageActivate(script.Dmg.Value, hit)
Exp = Exp + 15
LocalPlayer.PlayerGui.UI.Experience.ExpBar.Size = UDim2.new((Exp / 100) * 0, 0, 0.02, 0)
LocalPlayer.PlayerGui.UI.Experience.ExpBackground.ExpAmt.Text = Exp.."/100"
script.Disabled = true
end
end)
You're having the same issue as this guy.
When you create a variable based on a NumberValue's Value, you are storing a copy of the value, not a reference to it. If you want to update the value, you need to manually assign it.
local Exp = LocalPlayer.leaderstats.Experience
Exp.Value = Exp.Value + 15
local ExpGui = LocalPlayer.PlayerGui.UI.Experience
ExpGui.ExpBar.Size = UDim2.new((Exp.Value / 100) * 0, 0, 0.02, 0)
ExpGui.ExpBackground.ExpAmt.Text = tostring(Exp.Value) .. "/100"
Here's the error and what I've tried.
Error: Workspace.Part.Script:4: attempt to index nil with 'leaderstats'
My code:
Making Leaderstats:
game.Players.PlayerAdded:Connect(function(plr)
local ls = Instance.new("Model")
ls.Name = "leaderstats"
ls.Parent = plr
local m = Instance.new("IntValue")
m.Name = "Stars"
m.Value = 0
m.Parent = ls
end)
Touch Code:
local collected = false
script.Parent.Touched:Connect(function()
if collected == false then
game.Players.LocalPlayer.leaderstats.Stars.Value = game.Players.LocalPlayer.leaderstats.Stars.Value + 1
end
collected = true
end)
A server script would suit your need better. In a localscript, the change would only appear for the player. Also, it's better practice to use the Players service offered by Roblox. Here's an example:
local Players = game:GetService('Players')
local collected = false
script.Parent.Touched:Connect(function(partTouched)
if partTouched.Parent:IsA('Model') and partTouched.Parent:FindFirstChild('Humanoid') and partTouched:IsA('BasePart') then -- Is this a player? If so, then..
local player = Players:GetPlayerFromCharacter(partTouched.Parent)
if collected == false then
player.leaderstats.Stars.Value += 1 -- shorter syntax
end
collected = true
--script.Parent:Destroy() optional if this part won't be used again.
end
end)
If you're planning to use this for many parts, using a central ModuleScript would save you lots of changing things back and forth: https://developer.roblox.com/en-us/api-reference/class/ModuleScript