Where do I put my local script

when it send the obj to the server script it will not get it in the local script if I print obj.Name

attempt to index boolean with ‘Name’

2 Likes

Can you send me a place file of the game?

2 Likes

I can sent the whole script both

2 Likes

Sure, that would be better probably

2 Likes

in thye part sever script:

local sendChance = game:GetService("ReplicatedStorage").RemoteEvents.SendChanceRemoteEvent
local sendSound = game:GetService("ReplicatedStorage").RemoteEvents.ButtonSoundRemoteEvent
local inSound = true
local outSound = false
local debounce = false
local obj = script.Parent

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local character = hit.Parent
		if game:GetService("Players"):GetPlayerFromCharacter(character) then
			if debounce == false then
				debounce = true
				local player = game:GetService("Players"):GetPlayerFromCharacter(character)
				
				inSound = true
				outSound = false
				
				sendSound:FireClient(player, inSound, outSound, obj)

				local luckUpgrades = player.Values.LuckUpgrades.Value * 5
				local luck = luckUpgrades / 100 + 1

				local amountSteps = 2
				
				if player.Values.Steps.Value > 0 then
					for count = 1,player.Values.Steps.Value,1 do
						amountSteps *= 2.3
					end
				end
				
				amountSteps /= luck
				print(amountSteps)

				amountSteps = math.floor(amountSteps)
				print(amountSteps)
				
				if amountSteps < 1 then
					amountSteps = 1
				end

				local randomNumber = math.random(1,amountSteps)

				if randomNumber == 1 then
					player.Values.Steps.Value += 1
					local newChance = 2
					
					for count = 1,player.Values.Steps.Value,1 do
						newChance *= 2.3
					end

					newChance /= luck
					
					newChance = math.floor(newChance)
					sendChance:FireClient(player, newChance)
				elseif randomNumber > 1 then

					local chance = 2 / luck
					local newChance = math.floor(chance)
					sendChance:FireClient(player, newChance)

					local oldSteps = player.Values.Steps.Value
					player.Values.Steps.Value = 0
					local money = 1
					if oldSteps ~= 0 then
						for count = 1,oldSteps,1 do
							money *= 10
						end
						player.leaderstats.Money.Value += money
					end
				end
				
				inSound = false
				outSound = true

				sendSound:FireClient(player, inSound, outSound, obj)
				
				local secondOff = 0.02 * player.Values.CooldownUpgrades.Value
				local cooldown = 1 - secondOff

				wait(cooldown)
				
				debounce = false
			end
		end
	end
end)

local script:

local player = game:GetService("Players").LocalPlayer
local sendSound = game:GetService("ReplicatedStorage").RemoteEvents.ButtonSoundRemoteEvent

sendSound.OnClientEvent:Connect(function(obj)
	print(obj.Name)
	if typeof(obj) == "Instance" and obj:IsA("Part") then
		obj.Position = Vector3.new(obj.Position.X, obj.Position.Y - 0.25, obj.Position.Z)

		local secondOff = 0.02 * player.Values.CooldownUpgrades.Value
		local cooldown = 1 - secondOff

		wait(cooldown)

		obj.Position = Vector3.new(obj.Position.X, obj.Position.Y + 0.25, obj.Position.Z)
	end
end)
3 Likes

My apologies man, I was doing something earlier.

Anyway, here are the fixed versions of your script:

LocalScript:

local player = game:GetService("Players").LocalPlayer
local sendSound = game:GetService("ReplicatedStorage").Folder.ButtonSoundRemoteEvent

sendSound.OnClientEvent:Connect(function(sound, obj)
	if typeof(obj) == "Instance" and obj:IsA("Part") then
		obj.Position = Vector3.new(obj.Position.X, obj.Position.Y - 0.25, obj.Position.Z)
		if typeof(sound) == "Instance" and sound:IsA("Sound") then
			sound:Play()
		end

		-- local secondOff = 0.02 * player.Values.CooldownUpgrades.Value
		local cooldown = 1 -- secondOff

		wait(cooldown)


		obj.Position = Vector3.new(obj.Position.X, obj.Position.Y + 0.25, obj.Position.Z)
	end
end)

ServerScript:

local sendChance = game:GetService("ReplicatedStorage").RemoteEvents.SendChanceRemoteEvent
local sendSound = game:GetService("ReplicatedStorage").RemoteEvents.ButtonSoundRemoteEvent

local debounce = false
local obj = script.Parent

local inSound = obj:WaitForChild("inSound")
local outSound = obj:WaitForChild("outSound")

obj.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local character = hit.Parent
		if game:GetService("Players"):GetPlayerFromCharacter(character) then
			if debounce == false then
				debounce = true
				local player = game:GetService("Players"):GetPlayerFromCharacter(character)

				sendSound:FireClient(player, inSound, obj)

				local luckUpgrades = player.Values.LuckUpgrades.Value * 5
				local luck = luckUpgrades / 100 + 1

				local amountSteps = 2

				if player.Values.Steps.Value > 0 then
					for count = 1,player.Values.Steps.Value,1 do
						amountSteps *= 2.3
					end
				end

				amountSteps /= luck
				print(amountSteps)

				amountSteps = math.floor(amountSteps)
				print(amountSteps)

				if amountSteps < 1 then
					amountSteps = 1
				end

				local randomNumber = math.random(1,amountSteps)

				if randomNumber == 1 then
					player.Values.Steps.Value += 1
					local newChance = 2

					for count = 1,player.Values.Steps.Value,1 do
						newChance *= 2.3
					end

					newChance /= luck

					newChance = math.floor(newChance)
					sendChance:FireClient(player, newChance)
				elseif randomNumber > 1 then

					local chance = 2 / luck
					local newChance = math.floor(chance)
					sendChance:FireClient(player, newChance)

					local oldSteps = player.Values.Steps.Value
					player.Values.Steps.Value = 0
					local money = 1
					if oldSteps ~= 0 then
						for count = 1,oldSteps,1 do
							money *= 10
						end
						player.leaderstats.Money.Value += money
					end
				end
				
				sendSound:FireClient(player, outSound, obj)

				local secondOff = 0.02 * player.Values.CooldownUpgrades.Value
				local cooldown = 1 - secondOff

				wait(cooldown)

				debounce = false
			end
		end
	end
end)
2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.