#could someone help? everytime i touch the chest i should get 1 win but nothing is happening

1 messages · Page 1 of 1 (latest)

ripe seal
grand spruceBOT
#

studio** You are now Level 4! **studio

forest kraken
#

Maybe try putting .OnServerEvent functions out of OnPlayerAdded function and make them global. And also use :WaitForChild in the variables

grand spruceBOT
#

studio** You are now Level 3! **studio

ripe seal
#

but if i do onplayeradded everyone who join will get a win right

forest kraken
#

No they wont

#

Cuz it's a seperate function in a function

ripe seal
#

so i just replace all the OnServerEvents with OnPlayerAdded?

forest kraken
#

No I meant that you should make the .OnServerEvent functions global

#

Meaning put them outside of OnPlayerAdded function

ripe seal
#

ohh

#

alright

#

it didnt work

forest kraken
#

Also you have to check if it's the exact player you want to add wins or else it is just gonna add wins to random players

#

Hmm

#

What is chest

ripe seal
#

btw im scripting for 2 weeks now so i dont really know things

forest kraken
#

Oh yea

ripe seal
#

chest is just a part

forest kraken
#

Put powerlesderstats function in

#

And put winevent out

#

Replace it with this

ripe seal
#

so i just put the wins.value in the powerleaderstats?

forest kraken
#

WinEvent.OnServerEvent:Connect(function(plr) plr.leaderstats.Wins.Value += 1 end)

ripe seal
#

alright

forest kraken
#

I'm on mobile so sorry if my typing speed slow

#

Now send me the script

ripe seal
#

local Players = game:GetService("Players")
local PowerLeaderstats = game.ReplicatedStorage.PowerLeaderstats
local WinEvent = game.ReplicatedStorage.WinEvent

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

local Power = Instance.new("IntValue")
Power.Name = "Power"
Power.Value = 0
Power.Parent = leaderstats

local Wins = Instance.new("IntValue")
Wins.Name = "Wins"
Wins.Value = 0
Wins.Parent = leaderstats

PowerLeaderstats.OnServerEvent:Connect(function()
    Power.Value = Power.Value + 1
end)
WinEvent.OnServerEvent:Connect(function(plr)
    plr.leaderstats.Wins.Value += 1
end)

end
Players.PlayerAdded:Connect(onPlayerAdded)

#

i will send ss so you can understand it better

forest kraken
#

Yea

ripe seal
forest kraken
#

I told you to put winevent function out

#

OHHH

#

i get it what's the problem

#

Local scritps doesn't works in workspace

ripe seal
#

its not in workspace tho

forest kraken
#

Ur prolly using a local script in a part that's in workspace

ripe seal
#

in in serverscript service

#

and its a normal script

forest kraken
#

It doesn't works there too

#

I'm talking about the local script

#

Not server

ripe seal
#

oh

#

wait

#

yea you're right

forest kraken
#

I'm always right 👽 😎

ripe seal
#

where do i put it then?

#

replicatedstorage?

forest kraken
#

Put it in Starter character script or StarterPlayerScritps

ripe seal
#

ok

forest kraken
#

Wait is chest in workspace?

ripe seal
#

yes

forest kraken
#

Then replace local Chest = script.Parent with
local Chest = --the location of chest in workspace

ripe seal
#

done

#

i will test it now

#

should work

forest kraken
#

Yes

ripe seal
#

still doesnt work 😔

forest kraken
#

Where did u put

#

Local script

ripe seal
#

starter character scripts

forest kraken
#

Copy and apste local script code

ripe seal
#

local WinEvent = game.ReplicatedStorage.WinEvent
local Chest = game.Workspace.Hitbox

Chest.Touched:Connect(function()
WinEvent:FireServer()
end)

forest kraken
#

Use :WaitForChild

#

Also is there any errors in output?

#

If yes then tell what is it

granite linden
#

i will exploit on your game for infinite wins when you release it

ripe seal
#

nope

ripe seal
forest kraken
ripe seal
#

its just for learning lua

forest kraken
ripe seal
#

i dont even have data store

#

but waitforchild is for the chest right?

forest kraken
#

Yea

ripe seal
#

ok

forest kraken
#

Also detect if hitbox is being touched or not

#

local WinEvent = game.ReplicatedStorage.WinEvent
local Chest = game.Workspace.Hitbox

Chest.Touched:Connect(function()
WinEvent:FireServer()
print(1)
end)

#

Now see if it prints 1

#

If it does then local script is working fine

ripe seal
#

its printing

forest kraken
#

Does it print 1

ripe seal
#

yep

forest kraken
#

Then problem is in server script

#

Try printing 2 in the last line of OnPlayerAdded function

#

And see if it does prints

granite linden
#

has anything changed from the first images he sent?

grand spruceBOT
#

studio** You are now Level 5! **studio

forest kraken
ripe seal
#

its printing

granite linden
#

can you send the current scripts 🤑

ripe seal
#

like everything?

#

its a total of 4 scripts i think

forest kraken
#

Yea send current script

ripe seal
#

ok gimme a sec

#

leaderstats

#

localscript for the chest to be touched

#

jumpheight counter in a gui

forest kraken
#

I said to use :WaitForChild in every variable

ripe seal
#

bcz i dont quite understand it in this script

forest kraken
#

Show me the output after u touch the chest

grand spruceBOT
#

studio** You are now Level 4! **studio

ripe seal
#

there is litaraly nothing

forest kraken
#

Oh

ripe seal
#

it does touch i think

forest kraken
#

Put winevent outside of OnPlayerAdded event

ripe seal
#

tried and it doesnt work but ill try again

#

like this right?

forest kraken
#

Yea

ripe seal
#

oh

#

well

#

it does work

forest kraken
#

yesir

ripe seal
#

tysm

forest kraken
#

Your welcome

ripe seal
#

just gotta add debounce to it

forest kraken
#

Will u do it?

ripe seal
#

yes i know how to do that luckely

forest kraken
#

Alright I need to sleep it's like 10pm

#

Bye