Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Does intValue change from script to local script?

Asked by 3 years ago
Edited 3 years ago

I have been having problems with the intvalue. So i made the leader board stats with coins and then some pads to buy multipliers(All using script). Then I made a portal for 3k and wanted to use local script so only people with the required amount of money can enter. This works as it is suppose to and when I bought the Portal I have 0 cash. However when I bought a multiplier , my money went back to 3k. Does this have to do with the change from script to local script? I can provide the code if you need. The game is basically collecting blocks and selling it for coins. Use the coins to buy multipliers

leaderboard script:

local function Join(player) local leaderstats = Instance.new("Folder") leaderstats.Name = "leaderstats" leaderstats.Parent = player

local blocks = Instance.new("NumberValue")
blocks.Name = "blocks"
blocks.Value = 0
blocks.Parent = leaderstats

local coins = Instance.new("NumberValue")
coins.Name = "coins"
coins.Value = 3000
coins.Parent = leaderstats

local multi = Instance.new("NumberValue")
multi.Name = "multi"
multi.Value = 1
multi.Parent = leaderstats

end

game.Players.PlayerAdded:Connect(Join)

multiply and sell script:

local function muliplyA(player) local blocks = player:WaitForChild("leaderstats"):WaitForChild("blocks") local coins = player:WaitForChild("leaderstats"):WaitForChild("coins") local multi = player:WaitForChild("leaderstats"):WaitForChild("multi") if coins.Value >= 10 and multiplier <5 then multiplier = multiplier + 0.1 coins.Value = coins.Value - 10 multi.Value = multiplier end end

local function touchA(Part) if game.Players:GetPlayerFromCharacter(Part.Parent) then muliplyA(game.Players:GetPlayerFromCharacter(Part.Parent)) end end

game.Workspace.Multipler.Touched:Connect(touchA)

local function Sell(player) local blocks = player:WaitForChild("leaderstats"):WaitForChild("blocks") local coins = player:WaitForChild("leaderstats"):WaitForChild("coins") local add = blocks.Value * multiplier coins.Value = coins.Value + add blocks.Value = 0 end

local function touched(Part) if game.Players:GetPlayerFromCharacter(Part.Parent) then Sell(game.Players:GetPlayerFromCharacter(Part.Parent)) end end

script.Parent.Touched:Connect(touched)

Portal script(local script):

local Players = game:GetService("Players")

local function TP(player) local coins = player:WaitForChild("leaderstats"):WaitForChild("coins") if coins.Value >= 3000 and player and game.Workspace.Teleport2.TP2.CanCollide == true then game.Workspace.Teleport2.TP2.CanCollide = false coins.Value = coins.Value - 3000 end end local function Active(Part) if game.Players:GetPlayerFromCharacter(Part.Parent) then TP(game.Players:GetPlayerFromCharacter(Part.Parent)) end end

game.Workspace.Teleport2.TP2.Touched:Connect(Active)

local function Tele(player) if player.Parent:FindFirstChildWhichIsA("Humanoid") and game.Workspace.Teleport2.TP2.CanCollide == false then player.Parent.Head.CFrame = CFrame.new(-121.5, 210, 1001) end end

game.Workspace.Teleport2.TP2.Touched:Connect(Tele)

local function Tele(player) if player.Parent:FindFirstChildWhichIsA("Humanoid") then player.Parent.Head.CFrame = CFrame.new(0,5,0) end end

game.Workspace.Back.TP2.Touched:Connect(Tele)

0
If you can provide the chunk of code that handles the purchasing of the multiplier as well as if the script is a localscript / serverscript that would be helpful. Foxbodys 0 — 3y
0
Sorry if its hard to read. All are server script except the teleport one which is local. The teleport/local script is in starter player scripts. JustinWe12 723 — 3y
0
The problem is ur trying to subtract the value with a local script, That is not possible to do, So if u want my suggestion i suggest making the local script fire a connection to a script that will subtract the players money TNTIsLyfe 152 — 3y

1 answer

Log in to vote
0
Answered by
TNTIsLyfe 152
3 years ago
Edited 3 years ago

The problem is ur trying to subtract the value with a local script, That is not possible to do, So if u want my suggestion i suggest making the local script fire a connection to a script that will subtract the players money Like for example pretend there is a remoteEvent in replicated Named Portals so ur local script would be. Also its just function not local function So u shouldnt put local function or else it could get confused. Also dont assign same names to functions or else it could maybe get the wrong function

local Players = game:GetService("Players")

function TP(player) local coins = player:WaitForChild("leaderstats"):WaitForChild("coins") if coins.Value >= 3000 and player and game.Workspace.Teleport2.TP2.CanCollide == true then game.Workspace.Teleport2.TP2.CanCollide = false 
local PortalPrice = 3000
game.ReplicatedStorage.Portals:FireServer(player,PortalPrice) 
end
end       
function Active(Part) if game.Players:GetPlayerFromCharacter(Part.Parent) then TP(game.Players:GetPlayerFromCharacter(Part.Parent)) end end

game.Workspace.Teleport2.TP2.Touched:Connect(Active)

function Tele(player) if player.Parent:FindFirstChildWhichIsA("Humanoid") and game.Workspace.Teleport2.TP2.CanCollide == false then player.Parent.Head.CFrame = CFrame.new(-121.5, 210, 1001) end end

game.Workspace.Teleport2.TP2.Touched:Connect(T)

function T(player) if player.Parent:FindFirstChildWhichIsA("Humanoid") then player.Parent.Head.CFrame = CFrame.new(0,5,0) end end

game.Workspace.Back.TP2.Touched:Connect(Tele)

And ServerScript in serverscriptservice would be

game.ReplicatedStorage.Portals.OnServerEvent:connect(function(player,Price)
player.leaderstats.coins.Value = player.leaderstats.coins.Value - Price
end)
Ad

Answer this question